- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 03:28 PM
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!
Solved! Go to Solution.
- Labels:
-
Service Catalog
-
Workflow

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:39 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 03:34 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:12 PM
Hi
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';
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:39 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-08-2022 04:45 PM