What is the symbol for contains in a script?

Kifrez
Kilo Guru

Hi

Could you please help me with the following script?
I would like to change to include 'contains' of the catalog item instead of equal to

gr.cat_item.name contains "User account" doesn't seem to be correct.

answer = ifScript();
function ifScript() {
	if (gr.cat_item.name == "User account" && gr.variables.business_unit == "IT") {
		return 'Yes';
	}
	return 'No';
}

Thanks for the help!

1 ACCEPTED SOLUTION

Hi, You’re assigned values before the gr query is happening so they will always be empty.

sorry for phone formatting 

answer = ifScript();
 function ifScript() { 
var gr = new GlideRecord("sc_req_item");

gr.addQuery("request", current.getUniqueValue());

gr.query(); 

if (gr.next()) { 
var catItemName = gr.cat_item.name.toString(); var businessUnit = gr.variables.business_unit.getDisplayValue(); 


if (catItemName.includes("User Account") && businessUnit == "IT"){ 
return 'yes';
} 
return 'no'; }
 }

 

It should be more like that.if you’re having issues still add some gs.logs and check the values of cat item name and business values at different points Hope this helps.

View solution in original post

8 REPLIES 8

Thanks @Dan H , that seems to work.

Thanks for explaining that too. the knowledge will help me in future.

Hi @Freddy 

No problem. Glad it's working. If you wouldn't mind could you go ahead and mark my answer as correct?

Many thanks!

It's just weird that if multiple catalog items were added, sometimes the workflow works and other time won't work.

 

Would you happen to know why?

FYI, this if statement is on sc_request workflow.