Using Script Include on the Workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:17 AM - edited 12-12-2023 05:36 AM
Hi All,
We have the below script include as follows
var CheckDevProdCIenv_WF = Class.create();
CheckDevProdCIenv_WF.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCI: function(getAppname) {
////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;
},
type: 'CheckDevProdCIenv_WF'
});
Once the u_application_name is passed it would return the answer as I mean the CIlist should return Dev/Prod/ Test
I am trying to use the above SI in a workflow as below
gs.log("WF AppName " +current.variables.product.u_application_name);// this log returns right value
var CIlist = new CheckDevProdCIenv_WF().getCI(current.variables.product.u_application_name.toString());
gs.log("WF User CI ENv " +CIlist);// this does not work
it shows undefined only
I tried without .toString() also.
Please help us with the same.
TIA

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:18 AM - edited 12-12-2023 06:20 AM
As script include logs are correct, there is some issue with your local var name 'CIlist':
try below:
var ci_used_for= new CheckDevProdCIenv_WF().getCI(current.variables.product.u_application_name.toString());
gs.log("WF User CI ENv " +ci_used_for);// this does not work
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:11 AM
Hi @babarat1
I tested your Script include and I was able to get the expected result. I just replaces 'u_application_name' with 'name' on my PDI (I don't have that column).
Please check you have entered the correct column name that for table(cmdb_ci_service) query in your SI.
Thanks
Anil Lande

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:13 AM
This is what I have:
var CheckDevProdCIenv_WF = Class.create();
CheckDevProdCIenv_WF.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCI: function(getAppname) {
////var getAppname = this.getParameter('sysparm_app_name');
//var getsysid = this.getParameter('sysparm_sysid');
var grgetCI = new GlideRecord('cmdb_ci_service');
grgetCI.addEncodedQuery('name!=NULL'); // replaced column name here
grgetCI.addQuery('name', getAppname); // replaced column name here
grgetCI.query();
var CIlist = "";
while (grgetCI.next()) {
if (CIlist == '') {
CIlist = grgetCI.used_for.toString();
} else {
CIlist = CIlist + ", " + grgetCI.used_for.toString();
}
}
var answer = CIlist;
return answer;
},
type: 'CheckDevProdCIenv_WF'
});
Thanks
Anil Lande