- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:34 AM - edited 05-06-2025 02:36 AM
Hi Team,
I have this situation. I've trying to create a script in if condition to get my location send in my catalog form as below
Once i complete the form a workflow start run and i have IF condition where i'm passing several location
if true, go to next step. This is the code that i'm passing.
First of all i've tried with the name, "Wichita Falls", but not work and now i'm trying with sys_id. but not work too
// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
gs.log("Teste_1: " + current.localidad);
gs.log("Teste_2: " + current.location);
try {
answer = ifScript(current.localidad);
} catch (error) {
answer = ifScript(current.location);
}
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (location == "Wichita Falls") {
return 'yes';
} else if (location == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (location == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
} else if (location == "0d18b43287d86510fd54cb75dabb3557") {
return 'yes';
}
See the logs. All those "teste_1, 2 and 3" are undefined
Get Location?(391fbd5a479de210cbcc97a4116d43ad): org.mozilla.javascript.WrappedException: Wrapped ReferenceError: "location" is not defined. (// This script needs to set answer to 'yes' or 'no' to indicate the state of the activity.
//
// For example,
//
gs.log("Teste_1: " + current.localidad);
gs.log("Teste_2: " + current.location);
try {
answer = ifScript(current.localidad);
} catch (error) {
answer = ifScript(current.location);
}
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (location == "Wichita Falls") {
return 'yes';
} else if (location == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (location == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
} else if (location == "0d18b43287d86510fd54cb75dabb3557") {
return 'yes';
} else if (location == "0d18b43287d86510fd54cb75dabb355d") {
return 'yes';
} else if (location == "d518b43287d86510fd54cb75dabb358a") {
return 'yes';
} else if (location == "dd18b43287d86510fd54cb75dabb3594") {
return 'yes';
} else if (location == "d118b43287d86510fd54cb75dabb35a0") {
return 'yes';
} else if (location == "dd18b43287d86510fd54cb75dabb3585") {
return 'yes';
} else if (location == "d118b43287d86510fd54cb75dabb358e") {
return 'yes';
} else if (location == "d918b43287d86510fd54cb75dabb3595") {
return 'yes';
} else if (location == "c918b43287d86510fd54cb75dabb3551") {
return 'yes';
} else if (location == "e57e157437d0200044e0bfc8bcbe5d3d") {
return 'yes';
} else if (location == "aa3c89b037d0200044e0bfc8bcbe5d08") {
return 'yes';
} else if (location == "d118b43287d86510fd54cb75dabb3597") {
return 'yes';
} else {
return 'no';
}
}; line 18) (sys_script_include.365eca63c0a8016600069528aee5affb.script ➚; line 117)
Thank's advanced
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:38 AM - edited 05-06-2025 02:41 AM
You would need to use below syntax if you are trying to access catalog variable value in workflow:
current.variables.location
Also, as you have used 'loc' as variable in function, use the same in if conditions, currently you are suing 'location' variable which will throw error.
Something like below:
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (loc == "Wichita Falls") {
return 'yes';
} else if (loc == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (loc == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
}
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:40 AM - edited 05-06-2025 02:44 AM
Hi @Rafael Batistot
It should be current.variables.localidad and current.variables.location.
Try this and see.
gs.info("Teste_1: " + current.variables.localidad);
gs.info("Teste_2: " + current.variables.location);
try {
answer = ifScript(current.variables.localidad);
} catch (error) {
answer = ifScript(current.variables.location);
}
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (loc == "Wichita Falls") {
return 'yes';
} else if (loc == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (loc == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
} else if (loc == "0d18b43287d86510fd54cb75dabb3557") {
return 'yes';
}
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:38 AM - edited 05-06-2025 02:41 AM
You would need to use below syntax if you are trying to access catalog variable value in workflow:
current.variables.location
Also, as you have used 'loc' as variable in function, use the same in if conditions, currently you are suing 'location' variable which will throw error.
Something like below:
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (loc == "Wichita Falls") {
return 'yes';
} else if (loc == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (loc == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
}
Regards,
Abhijit
ServiceNow MVP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:53 AM
It works to me. Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:40 AM - edited 05-06-2025 02:44 AM
Hi @Rafael Batistot
It should be current.variables.localidad and current.variables.location.
Try this and see.
gs.info("Teste_1: " + current.variables.localidad);
gs.info("Teste_2: " + current.variables.location);
try {
answer = ifScript(current.variables.localidad);
} catch (error) {
answer = ifScript(current.variables.location);
}
function ifScript(loc) {
gs.log("Teste_3: " + loc);
if (loc == "Wichita Falls") {
return 'yes';
} else if (loc == "d518b43287d86510fd54cb75dabb3599") {
return 'yes';
} else if (loc == "8195ad7437d0200044e0bfc8bcbe5d8f") {
return 'yes';
} else if (loc == "0d18b43287d86510fd54cb75dabb3557") {
return 'yes';
}
}
Regards,
Siva
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2025 02:54 AM
I assume the variable name is "localidad" and "Wichita Falls" is the exact name of location and if it's that location then return yes or else return no
so use this script
answer = ifScript();
function ifScript() {
if (current.variables.localidad.getDisplayValue() == 'Wichita Falls')
return 'yes';
else
return 'no';
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader