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 05:25 AM
If current.product.u_application_name logs the expected value, why are you using current.variables.product.u_application_name in the function call? Is the Script Include in the Global Scope? If you add a log at the beginning of the Script Include can you confirm that it is running?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:41 AM
Hi,
Thanks for the reply. It was not just current.product, it was current.variables.product.u_application_name); and the log returns right value. I have updated my Post as well.
It is a Global SI
And I tried to have the log in first place
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 05:57 AM
That's a good start. Add some more logging to see what's going on:
getCI: function(getAppname) {
gs.log('SI Appname = ' + getAppname);
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()){
gs.log('SI inside while');
if(CIlist == ''){
CIlist = grgetCI.used_for.toString();
}
else
{
CIlist = CIlist + ", "+ grgetCI.used_for.toString();
}
}
var answer = CIlist;
gs.log('SI answer = ' + answer);
//JSON.stringify(answer);
//return JSON.stringify(answer);
return answer;
},
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2023 06:14 AM
Hi Brad,
Yes all of the logs returns right values