Using Script Include in Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 12:46 AM - edited 12-07-2023 05:29 AM
Hello All,
I have the below script include which I use on On change catalog client script
SI::
getCI: function() {
var getAppname = this.getParameter('sysparm_app_name');
var getsysid = this.getParameter('sysparm_sysid');
var grgetCI = new GlideRecord('cmdb_ci_service');
grgetCI.addEncodedQuery('u_application_name!=NULL');
grgetCI.addQuery('u_application_name',getAppname);
grgetCI.query();
var CIlist = "";
while(grgetCI.next()){
if(CIlist == ''){
CIlist = grgetCI.used_for.toString();
}
else
{
CIlist = CIlist + ", "+ grgetCI.used_for.toString();
}
}
var answer = CIlist;
//JSON.stringify(answer);
return JSON.stringify(answer);
//return answer;
},
And on the Client script I pass the parameter getAppname - with g_form.product variable
The above script include returns the value of Used for - Prod/Dev/test from Business Service
Now, I have the same logic to be applied from workflow and I want the same return values from the script include that would return the Used for of a Business Service when we pass the current.variables.product field from workflow
How to achieve the same?
TIA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 12:53 AM
Hi @DPrasna ,
U can create a new Script include with client callable as false (Deactivate the existing one or delete it)& then paste the same code which u have shared above. The only difference would be this
getCI: function(appName,sysID) {
var getAppname = appName;
var getsysid = sysID;
var grgetCI = new GlideRecord('cmdb_ci_service');
grgetCI.addEncodedQuery('u_application_name!=NULL');
grgetCI.addQuery('u_application_name',getAppname);
grgetCI.query();
var CIlist = "";
while(grgetCI.next()){
if(CIlist == ''){
CIlist = grgetCI.used_for.toString();
}
else
{
CIlist = CIlist + ", "+ grgetCI.used_for.toString();
}
}
var answer = CIlist;
//JSON.stringify(answer);
return JSON.stringify(answer);
//return answer;
},
& from ur workflow u can call the script include using this command.
var response = new ScriptIncludeName().getCI(current.variable.appName,current.sysID);//please use proper script & variable names as per your requirement
Thanks,
Danish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 12:54 AM
Hi @DPrasna ,
Refer below community post.
Please check and Mark Helpful and Correct if it really helps you.
Regards,
Mayur Shardul
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 12:54 AM
you need to update the function as this so that it works from both client and server
getCI: function(getAppname1,getsysid1) {
var getAppname = this.getParameter('sysparm_app_name') || getAppname1;
var getsysid = this.getParameter('sysparm_sysid') || getsysid1;
var grgetCI = new GlideRecord('cmdb_ci_service');
grgetCI.addEncodedQuery('u_application_name!=NULL');
grgetCI.addQuery('u_application_name',getAppname);
grgetCI.query();
var CIlist = "";
while(grgetCI.next()){
if(CIlist == ''){
CIlist = grgetCI.used_for.toString();
}
else
{
CIlist = CIlist + ", "+ grgetCI.used_for.toString();
}
}
var answer = CIlist;
//JSON.stringify(answer);
return JSON.stringify(answer);
//return answer;
},
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-04-2023 02:00 AM
Thanks for the reply. How to call the SI from WF?
var cc = new YourScriptIncludeName();
var ci_list = cc.getCI(current.variables.product);
Is this the right way?