Compare variable value and in a variable set variable value
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 06:05 AM - edited 03-07-2025 06:12 AM
Hi All,
Hi All,
I am currently working on a requirement that involves the following:
- A normal variable: assistant_name_to_add
- A variable from a variable set (people_supported_and_level_of_access), which contains a variable: names_of_the_people_supported
I am trying to compare these two variables and clear the values through an onChange script if they are the same. However, I am encountering an issue where the People Support variable is returning an empty value in the alert, even though it has a value.
Below is the code I am using:
Could you please review the code and let me know what I might be missing?
Your assistance in this matter would be greatly appreciated.
Thank you in advance for your help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 06:24 AM
Hi @Sirri ,
1. can you try to check the both of the variables values and data types.
2. check the names of the columns.
try to do some debugging to get compare values
var removeassistant = g_form.getValue('assistant_name_to_add');
var peoplesupport = g_form.getValue('people_supported_and_level_of_access.names_of_the_people_supported');
var action = g_form.getValue('action');
gs.info("Remove Assistant: " + removeassistant);
gs.info("People Support: " + peoplesupport);
gs.info("Action: " + action);
if (!peoplesupport) {
gs.info("People Support is empty or undefined");
}
if (removeassistant == peoplesupport) {
g_form.clearValue('assistant_name_to_add');
g_form.showFieldMsg('assistant_name_to_add', 'Assistant or Delegate Name to Add and Names of the people supported cannot be the same.', 'error');
}
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 08:31 AM
Thank you for your response,
As per your script we cannot use gs in client script due to that we have used alert I'm value as empty for peoplesupport, Please try from your side and provide the exact script so It can help to me.
Thank you
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 08:37 AM
Hi @Sirri ,
try to use the client side functions for debugging like g_form.addInfoMessage.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2025 08:56 AM
I have shared the out put please check and provide the exact code. so I can test.
thank you