Script to parse output from Read File activity

tsutherland
Kilo Sage

I am using the custom SSH activity File Read in a workflow. It successfully connects and retrieves the file contents but when I try to check the output using this script

var obj = data.get(7).output;
var str = JSON.stringify(obj);
gs.log("The object " + str);
workflow.scratchpad.linux = str;

The next If statement returns an error 'undefined.'

 answer = ifScript();

   function ifScript() {
      if (workflow.scratchpad.linux.indexOf(workflow.scratchpad.user) > -1) {
        return 'yes';
      }
      return 'no';
   }

Error from logs

If Linux Account exists(8f10bd86dba4e11025f351fcd396194c): org.mozilla.javascript.WrappedException: Wrapped ConversionError: The undefined value has no properties. ( answer = ifScript();

function ifScript() {
if (workflow.scratchpad.linux.indexOf(workflow.scratchpad.user) !== -1) {
return 'yes';
}
return 'no';
}; line 4) (sys_script_include.365eca63c0a8016600069528aee5affb.script; line 117)

 This is the same script I use when parsing a Query AD activity so maybe that is my problem. I'm not yet very good at scripting so my process is to copy and tweak what I know works.

What am I doing wrong here?

1 ACCEPTED SOLUTION

Vishal Jawalka1
Tera Expert

Hi @tsutherland  - looks like the issue is with the data mapping.

the validation is : either data.get(**).result ( which will show you result ) or data.get(**).contents ( this will show you content of the output ).

 

Based on this you can find out the index of user you are seeking. you can also use .includes() method instead of index of.

View solution in original post

3 REPLIES 3

Vishal Jawalka1
Tera Expert

Hi @tsutherland  - looks like the issue is with the data mapping.

the validation is : either data.get(**).result ( which will show you result ) or data.get(**).contents ( this will show you content of the output ).

 

Based on this you can find out the index of user you are seeking. you can also use .includes() method instead of index of.

It was really helpful. I have fixed this issue with the help of this.

Thank you