Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

To call a script include using a flow

suuriyas
Tera Contributor

HI Community,

 

I have a requirement, i have created one script include what it does is it will create a sla record in sandbox instances (integration) when it is called. i have tested the script include in background script it works fine no issue.

Now i need to call that script include from flow have been trying many ways but i'm not able to achieve it.

so when the request is raised from a catalog item then in sandbox instances sla record need to be created and with the catalog variables like name type target these will get populate in sla record form and record is created.

 

what is the issue im facing is im not able to get the sysid of the ritm and pass it

Flow;

trigger condition service catalog

then created one custom action in that script step i have added like this

(function execute(inputs, outputs) {
var reqSysId = inputs.requestSysId;
gs.info('debug request sysid' + reqSysId );
if(!reqSysId){
    gs.error('debug error: flow didnot recieve request sysid');
    return;
}
var ritm = new GlideRecord('sc_req_item');
//ritm.addQuery('request', requestSysId);
//ritm.query();
if(!ritm.get(reqSysId)){
    gs.error('debug no ritm found' + reqSysId );
    return;
}
//while(ritm.next())
try{
    gs.info ('debug caling si for' + ritm.number);
    var util = new SLAIntegrationUtil();
        util.createSLADefinitions(ritm);
        gs.info('debug si completed for' + ritm.number);
    } catch(ex){
        gs.error(ex);
    }

})(inputs, outputs);
and input as 

suuriyas_0-1764066505918.png
But in log it is showing as undefined and record is not getting created.
Please help me how to fix it
 
Thanks in advance 
2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@suuriyas 

are you passing the RITM SysId properly to that custom flow action?

ensure everything is in lowercase in input variable i.e. Label and Name here -> Give it as requestsysId

AnkurBawiskar_0-1764067527093.png

 

then update script as this

var reqSysId = inputs.requestsysId;

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar ,

 

Thanks for the response 

Yes i have checked it is correct only but still im getting undefined 

suuriyas_0-1764069271110.pngsuuriyas_1-1764069318372.png

(function execute(inputs, outputs) {
var reqSysId = inputs.requestsysid;
//var reqSysId = '2f19ddfdeb59be10b2bff25e1bd0cd89';
gs.info('debug request sysid' + reqSysId );
if(!reqSysId){
    gs.error('debug error: flow didnot recieve request sysid');
    return;
}
var ritm = new GlideRecord('sc_req_item');
//ritm.addQuery('request', requestSysId);
//ritm.query();
if(!ritm.get(reqSysId)){
    gs.error('debug no ritm found' + reqSysId );
    return;
}
//while(ritm.next())
try{
    gs.info ('debug caling si for' + ritm.number);
    var util = new SLAIntegrationUtil();
        util.createSLADefinitions(ritm);
        gs.info('debug si completed for' + ritm.number);
    } catch(ex){
        gs.error(ex);
    }

})(inputs, outputs);
 
if i hardcoded the sysid then it is working fine sla record is getting created seems issue is with the first line alone not sure how to get the sysid