Compare variable value and in a variable set variable value

Sirri
Tera Guru

Hi All,

 

Hi All,

 

I am currently working on a requirement that involves the following:

  1. A normal variable: assistant_name_to_add
  2. 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:

 

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');

    alert("Remove Assistant: " + removeassistant);
    alert("People Support: " + peoplesupport);
    alert("Action: " + action);

    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');
    }
 

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.

 
13 REPLIES 13

Pavankumar_1
Mega Patron

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');
}

 

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

@Pavankumar_1 ,

 

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

Hi @Sirri ,

try to use the client side functions for debugging like g_form.addInfoMessage.

If it helps please click Accept as Solution/hit the Thumb Icon.
ServiceNow Community MVP 2024.
Thanks,
Pavankumar

@Pavankumar_1 ,

 

I have shared the out put please check and provide the exact code. so I can test. 

 

thank you