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

Dan H
Tera Guru

Hi,

Can you try:

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

Hope this helps.

Please mark my answer as Correct/Helpful based on impact

Regards,

Dan H

Hi @Dan H thanks for your response.

However, it didn't seem to work.
Actually my original script was

answer = ifScript();
function ifScript() {
	var gr = new GlideRecord("sc_req_item");
	gr.addQuery("request", current.getUniqueValue());
	gr.query();
	if (gr.next()) {
		if (gr.cat_item.name == "User Account" && gr.variables.business_unit.getDisplayValue() == "IT") {
			return 'yes';
		}
		return 'no';
	}
}

 

This is what I change my script to as below

answer = ifScript();
function ifScript() {
	var gr = new GlideRecord("sc_req_item");
        var catItemName = gr.cat_item.name.toString();
 	var businessUnit = gr.variables.business_unit.getDisplayValue();
	gr.addQuery("request", current.getUniqueValue());
	gr.query();
	if (gr.next()) {
		if (catItemName.includes("User Account") && businessUnit == "IT") {
			return 'yes';
		}
		return 'no';
	}
}

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.

Updated script