How to call script include in flow designer to call flow again

shweta14
Tera Contributor

I have requirement to call flow inside flow and add approval
I am creating multiple RITM based on list collector field and want to add same flow on each RITM to add approval and update record.

added below script include but not working
same script if run in background then it will work

script include :

-----------------------------------

var StartFlow = Class.create();
StartFlow.prototype = {
   // initialize: function() {
        startflow:function() {
   
    try {
        var gr=new GlideRecord('sc_req_item');
        if(gr.get('sys_id')){
       // gr.get('sys_id');
        var inputs = {};
        inputs['table_name'] = 'sc_req_item';
        inputs['request_item'] = gr; // GlideRecord of table: sc_req_item

        // Start Asynchronously: Uncomment to run in background.
        // sn_fd.FlowAPI.getRunner().flow('global.test_for_item').inBackground().withInputs(inputs).run();
               
        // Execute Synchronously: Run in foreground.
        sn_fd.FlowAPI.getRunner().flow('global.test_for_item').inForeground().withInputs(inputs).run();
        }
    } catch (ex) {
        var message = ex.getMessage();
        gs.error(message);
    }
 },
   // },

    type: 'StartFlow'
};
----------------------------------------------

how to achieve this? @Anil Lande 

8 REPLIES 8

RAMANA MURTHY G
Mega Sage
Mega Sage

Hello @shweta14 ,

 

If you want to call script include from flow, you can add script action (we have script button on every action) and try to write below code

new StartFlow ().startflow();       // StartFlow is your script include and startflow is a function written in script include

 

Please mark my answer as helpful & correct, if it helps you

Thank you

 

Please mark my answer helpful  & correct if it helps you
Thank you

G Ramana Murthy
ServiceNow Developer

can we use set flow variable instead of creating action
and if we use action then what should be the input 

shweta14_0-1714397428210.png

 

set flow variable script is working but when call flow for second record showing below error on flow(no record found)same script if i run background then there is no error @Ankur Bawiskar 
how to solve this?

shweta14_0-1714456885726.png

 

Hi @shweta14 

 

From background script it will work because your passing the value hardcoded and hence it will work as expected. Here whats happening is that your value is not being passed to the flow to process. 

 

Before the execution on your script logic try to log or print the variable value to see if it holds some value or its just being passed empty. 

 

If it holds value it must work as it worked in background. Try to log and catch the fix

 

I hope this helps 🙂


☑️ Please mark responses as HELPFUL or ACCEPT SOLUTION to assist future users in finding the right solution....

LinkedIn - Lets Connect