how to pass the parameter value of script include from workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 05:55 AM
Hi All,
I have the below script include and I use it from a catalog client script where I was able to pass a variable field value as parameter from client side.
I was thinking to re-use the same Script Include for another purpose which I need to use from Workflow because the return value is all I need to use.
However I am not sure how to pass the parameter value from Workflow.
Need help on the same.
TIA
var getAppname = this.getParameter('sysparm_app_name');//need help here
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-28-2023 06:22 AM
Call the SI from the workflow with one or more arguments like this using current.variable.var_name, current.field_name, and/or static values:
new siName().siFunction(current.variables.var_name);
Change your function declaration in the SI to include (each) argument, then the script will use one or the other - whichever is populated:
siFunction: (myValue) {
var getAppname = myValue;
if (getAppname == '') {
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();
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 05:46 AM
Hi Brad,
Thanks for the reply. And sorry I was out.
I changed the script as mentioned below
getCI: function(myValue) {
var getAppname = myValue;
if (getAppname == '') {
getAppname = this.getParameter('sysparm_app_name');
}
//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;
},
However I had a client script which was working before the script change which does not work now
Could you please help?
Client script:
var ga = new GlideAjax('Checkenv');
ga.addParam("sysparm_name", "getCI");
ga.addParam("sysparm_app_name", prod.u_application_name);
ga.addParam("sysparm_sysid", newValue);
//alert(newValue);
//alert(newValue.getDisplayValue());
ga.getXML(getResponse);
function getResponse(response) {
var res = response.responseXML.documentElement.getAttribute("answer");
//alert(res);
}
Also, the workflow - log does not show any value at all
Workflow :
var getCIEnv = new Checkenv().getCI(current.variables.product);
gs.log("CI ENv " +getCIEnv);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 06:12 AM
Try adding some log lines to the SI at the beginning for myValue and after the if for getAppname so you can see both values for each test case. I am using this structure, but maybe in this case myValue then getAppname is not '' but is null, so getAppname is not getting set? prod.u_application_name looks suspicious without seeing the full script. Is sysparm_app_name getting to the SI correctly? Is the product variable the same type as the prod.u_application_name field, or is it sending the wrong value to the SI? Also, CIlist is a string variable so you don't need to stringify it and can just return CIlist, which would help to log also so you know if anything is being sent back to the client/workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-30-2023 06:18 AM
Ok sure, let me try that.
Thanks