How to check if a catalog variable is present the RITM in workflow

rshegde
Mega Contributor

Hi,

In the workflow, I want to check if a particular catalog variable is present in RITM. how can I check that?

Regards,

Rajeev

4 REPLIES 4

larstange
Mega Sage

Hi



In your script you can check for



if (workflow.variables.var_name != undefined)


Ankur Bawiskar
Tera Patron
Tera Patron

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


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hi Ankur,



I want to check if the variable is present in the ritm.



Regards,


Rajeev


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


Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader