<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: javascript return context key from variable in Cortex XSOAR Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/495067#M925</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/218893"&gt;@Antanas&lt;/a&gt;, Just use the `!ConvertTableToHTML table=${newList} title="HTML Table"` command. You do not need to use the extend-context option since the code pass data to context under the&amp;nbsp;HTMLTable key.&lt;/P&gt;</description>
    <pubDate>Tue, 31 May 2022 07:23:25 GMT</pubDate>
    <dc:creator>jfernandes1</dc:creator>
    <dc:date>2022-05-31T07:23:25Z</dc:date>
    <item>
      <title>javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/491730#M875</link>
      <description>&lt;P&gt;Hi!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have modified a simple Javascript automation, however i can't seem to put an input value as a context key. In the below sample i declare&amp;nbsp; &lt;STRONG&gt;var Key = args.parent;&lt;/STRONG&gt; and in the &lt;STRONG&gt;return&lt;/STRONG&gt; statement i try to use this variable as context entry.&lt;/P&gt;&lt;P&gt;In reality, I literally get the context set to "&lt;STRONG&gt;Key&lt;/STRONG&gt;", regardless on what I specify in the input. It is like the input variable is disregarded. What am i missing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var data = args.data;
var Key = args.parent;
var headers = args.columns ? args.columns.split(',') : null;
if(!Array.isArray(data)) {
    data = [data];
}
var flatData = [];
data.forEach(function(element) {
  var flattenObject = treeToFlattenObject(element);
  flatData.push(flattenObject);
});
return {Type: entryTypes.note, Contents: tableToMarkdown(args.title, flatData, headers), ContentsFormat: formats.markdown,
    EntryContext: { Key : tableToHTML(args.title, flatData, headers)}};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Antanas&lt;/P&gt;</description>
      <pubDate>Wed, 25 May 2022 15:28:35 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/491730#M875</guid>
      <dc:creator>Antanas</dc:creator>
      <dc:date>2022-05-25T15:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/492125#M876</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/218893"&gt;@Antanas&lt;/a&gt;, I'm guessing you're trying to modify the ToTable automation to save the data to a context key. I would suggest using the extent-context like this&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;!ToTable data=${File} columns="name,size" title="This is a table" extend-context=data=&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you still need to get the automation working, could you send me the yml file?&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 02:27:31 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/492125#M876</guid>
      <dc:creator>jfernandes1</dc:creator>
      <dc:date>2022-05-26T02:27:31Z</dc:date>
    </item>
    <item>
      <title>Re: javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494353#M887</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/208028"&gt;@jfernandes1&lt;/a&gt;,&amp;nbsp;for some reason extend-context does not work in this case. I specifically try extend-context=NewKey=Key Including the yml code, much appreciated for any ideas.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;commonfields:
  id: 411b260b-c237-4b2c-8e12-3b0393af2e3e
  version: 2
vcShouldKeepItemLegacyProdMachine: false
name: ToHTMLTable_custom
script: |+
  var data = args.data;
  var Key = args.parent;
  var headers = args.columns ? args.columns.split(',') : null;
  if(!Array.isArray(data)) {
      data = [data];
  }
  var flatData = [];
  data.forEach(function(element) {
    var flattenObject = treeToFlattenObject(element);
    flatData.push(flattenObject);
  });
  return {Type: entryTypes.note, Contents: tableToMarkdown(args.title, flatData, headers), ContentsFormat: formats.markdown,
      EntryContext: { Key : tableToHTML(args.title, flatData, headers)}};

type: javascript
tags:
- Utility
comment: Convert an array to a nice table display. Usually, from the context.
enabled: true
args:
- name: data
  required: true
  description: The data to display as table - expecting array of objects
  isArray: true
- name: title
  description: Title for the table
- name: columns
  description: Comma-separated list of columns to display. Accepts nested columns
    using dot notation.
- name: parent
  required: true
  description: Context Key to store output
scripttarget: 0
pswd: ""
runonce: false
runas: DBotWeakRole
engineinfo: {}
mainengineinfo: {}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 29 May 2022 12:09:37 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494353#M887</guid>
      <dc:creator>Antanas</dc:creator>
      <dc:date>2022-05-29T12:09:37Z</dc:date>
    </item>
    <item>
      <title>Re: javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494426#M889</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/218893"&gt;@Antanas&lt;/a&gt;, I don't this you're using it right. Refer to the below screenshot. You do not need to specify a key after the "data=".&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-05-30 at 12.52.34 pm.png" style="width: 845px;"&gt;&lt;img src="https://live.paloaltonetworks.com/t5/image/serverpage/image-id/41476i98B020BB30CE1349/image-dimensions/845x199/is-moderation-mode/true?v=v2" width="845" height="199" role="button" title="Screen Shot 2022-05-30 at 12.52.34 pm.png" alt="Screen Shot 2022-05-30 at 12.52.34 pm.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I still recommend the above method, but in case you want, I've corrected the code too.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I found a couple of issues with the script.&lt;/P&gt;&lt;P&gt;1. You cannot use 'parent' as a variable since it's a reserved word. Refer - &lt;A href="https://www.w3schools.com/js/js_reserved.asp" target="_blank"&gt;https://www.w3schools.com/js/js_reserved.asp&lt;/A&gt;&lt;/P&gt;&lt;P&gt;2. I had to change the output of your script a little. Still not sure why yours did not work.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;commonfields:
  id: 411b260b-c237-4b2c-8e12-3b0393af2e3e
  version: 7
vcShouldKeepItemLegacyProdMachine: false
name: ToHTMLTable_custom
script: |
  var data = args.data;
  var Key = args.outputKey;
  var headers = args.columns ? args.columns.split(',') : null;
  if(!Array.isArray(data)) {
      data = [data];
  }
  var flatData = [];
  data.forEach(function(element) {
    var flattenObject = treeToFlattenObject(element);
    flatData.push(flattenObject);
  });
  var ec = {};
  ec[Key] = tableToHTML(args.title, flatData, headers);
  return {
      Type: entryTypes.note,
      Contents: tableToMarkdown(args.title, flatData, headers),
      ContentsFormat: formats.markdown,
      EntryContext: ec
  };
type: javascript
tags:
- Utility
comment: Convert an array to a nice table display. Usually, from the context.
enabled: true
args:
- name: data
  required: true
  description: The data to display as table - expecting array of objects
  isArray: true
- name: title
  description: Title for the table
- name: columns
  description: Comma-separated list of columns to display. Accepts nested columns
    using dot notation.
- name: outputKey
  required: true
  description: Context Key to store output
scripttarget: 0
pswd: ""
runonce: false
runas: DBotWeakRole
engineinfo: {}
mainengineinfo: {}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 03:18:04 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494426#M889</guid>
      <dc:creator>jfernandes1</dc:creator>
      <dc:date>2022-05-30T03:18:04Z</dc:date>
    </item>
    <item>
      <title>Re: javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494542#M892</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/208028"&gt;@jfernandes1&lt;/a&gt;&amp;nbsp;- your updated script works perfectly fine - thanks! BTW, you still suggested to use extend-context which works after I removed the Key variable. However (I guess) it extends the normal output (seen as piped variables), and not the EntryContext, which should be an HTML table code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 30 May 2022 08:25:31 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/494542#M892</guid>
      <dc:creator>Antanas</dc:creator>
      <dc:date>2022-05-30T08:25:31Z</dc:date>
    </item>
    <item>
      <title>Re: javascript return context key from variable</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/495067#M925</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/218893"&gt;@Antanas&lt;/a&gt;, Just use the `!ConvertTableToHTML table=${newList} title="HTML Table"` command. You do not need to use the extend-context option since the code pass data to context under the&amp;nbsp;HTMLTable key.&lt;/P&gt;</description>
      <pubDate>Tue, 31 May 2022 07:23:25 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/javascript-return-context-key-from-variable/m-p/495067#M925</guid>
      <dc:creator>jfernandes1</dc:creator>
      <dc:date>2022-05-31T07:23:25Z</dc:date>
    </item>
  </channel>
</rss>

