How to check if a catalog variable is present the RITM in workflow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 12:44 AM
Hi,
In the workflow, I want to check if a particular catalog variable is present in RITM. how can I check that?
Regards,
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 12:50 AM
Hi
In your script you can check for
if (workflow.variables.var_name != undefined)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 12:51 AM
Hi Rajeev,
The workflow I assume will run on RITM table and which is tagged to particular Catalog Item
You can check whether there is any value in that variable while user submitted the request as follows
Run Script activity with script below
if(current.variables.<variableName> != ''){
// variable has value
}
Is this your requirement?
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 12:53 AM
Hi Ankur,
I want to check if the variable is present in the ritm.
Regards,
Rajeev
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-12-2017 01:02 AM
Hi Rajeev,
So following code will help you whether the RITM or the Catalog Item tagged to this RITM is having the variable or not.
In the below example I have taken all the variables belonging to the current catalog item i.e. the workflow running on RITM in an array
and then using ArrayUtil determined whether the variable you want to find is present in that array or not
// assuming your workflow is on RITM table so current refers to ritm record
var variablesArray = [];
var item = new GlideappCatalogItem.get(current.cat_item); // sys id of the catalog item
var variables = item.getVariables();
while(variables.next())
{
var variable = variables.name.toString();
variablesArray.push(variable);
}
gs.log('Variables Array is:'+variablesArray);
var variableNameToBeSearched = 'heello';
var arrayUtil = new ArrayUtil();
var found = arrayUtil.contains(variablesArray,variableNameToBeSearched);
gs.log('Variable found:'+found);
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader