Adding flow script to flow

Mohammed Masi U
Tera Contributor

Hi All,

 

  • I'm creating an inbound email action using flow to load data from email attachment(.xlsx) and transform data. 

  • I'm trying to query Transform history table to get "import set run" details using look up Record action. It returns "Record not found".

 

  • Since look up record action is not working. I'm now using flow action---Script step to get the required data.

Sample code:

(function execute(inputs, outputs) {
 
var ImportSysId = inputs.ImportSetSysId;
var gr = new GlideRecord("sys_import_set_run");
gr.addQuery('set.sys_id', ImportSysId);
gr.query();

if(gr.next()){

var ignore = gr.getValue('ignored');

}

outputs.ignored = ignore;

})(inputs, outputs);
 
Above code works fine and gets me the desired output when tested in flow action. However, when I call this in Flow, it gives empty output.

 

Snip of flow that gives no value in "Ignore" output.

MohammedMasiU_0-1700689568162.png

 

Snip of test performed in Flow Action which return value as 10:

MohammedMasiU_1-1700690048647.png

 

Kindly help me resolve this.

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @Mohammed Masi U 

Is the import set sys_id is always constant? If not, If you are passing it dynamically based on the execution of transform, there might be a chance that the transform is not completed by the time this action is executed. Can you also change your code a bit like the one below and test.

 

(function execute(inputs, outputs) {

var ImportSysId = inputs.ImportSetSysId;

var gr = new GlideRecord("sys_import_set_run");

gr.addQuery('set.sys_id', ImportSysId);

gr.query();

var ignore = -1;

if(gr.next()){

   ignore = gr.getValue('ignored');

}

outputs.ignored = ignore;

})(inputs, outputs);

 

 

After updating the code, perform a test run, if you get -1 as the output it means the transform is not completed.

 

Can you also share snips of your flow, it would be more easy to understand and help you better?

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

View solution in original post

2 REPLIES 2

AnveshKumar M
Tera Sage
Tera Sage

Hi @Mohammed Masi U 

Is the import set sys_id is always constant? If not, If you are passing it dynamically based on the execution of transform, there might be a chance that the transform is not completed by the time this action is executed. Can you also change your code a bit like the one below and test.

 

(function execute(inputs, outputs) {

var ImportSysId = inputs.ImportSetSysId;

var gr = new GlideRecord("sys_import_set_run");

gr.addQuery('set.sys_id', ImportSysId);

gr.query();

var ignore = -1;

if(gr.next()){

   ignore = gr.getValue('ignored');

}

outputs.ignored = ignore;

})(inputs, outputs);

 

 

After updating the code, perform a test run, if you get -1 as the output it means the transform is not completed.

 

Can you also share snips of your flow, it would be more easy to understand and help you better?

 

Please mark my answer helpful and accept as a solution if it helped 👍

Thanks,
Anvesh

Hi @AnveshKumar M , 

Thank you for your response.

 

Your assumption was true, Transform was not being executed till the time action is being processed. 

I've now added a wait condition before the transform action and it worked perfectly!

Appreciate your help!