g_form.getValue is not working

Saurav Bhardwa2
Tera Contributor

Hello, 

I have written this client script on catalog variable set.

function onChange(control, oldValue, newValue, isLoading) {
  
var at = g_form.getValue('type');
console.log('test12 ' + at);
if(at == 'Modify Existing'){
g_form.showFieldMsg('type' , 'Your existing access will be removed and the new access will be added.' , 'info');
}
 
   //Type appropriate comment here, and begin script below
   
}
When I am checking the value for type, it's not returning anything in the background. Please check the snip below
Below are the choices-
SauravBhardwa2_0-1694065265795.png

Here's another snip of the logs

SauravBhardwa2_1-1694065315723.png

 

Also, I have tried to remove the space from the value of options but it didn't help
May I know if this is a expected behaviour?
1 ACCEPTED SOLUTION

Siva Jyothi M
Mega Sage

Hi @Saurav Bhardwa2,

 

Try the below script.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue == 'Modify Existing') {
        g_form.showFieldMsg('type', 'Your existing access will be removed and the new access will be added.', 'info');
    }

}

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.

View solution in original post

3 REPLIES 3

Hemanth M1
Giga Sage
Giga Sage

Hi @Saurav Bhardwa2 ,

 

I would use newValue instead g_form.getVlaue() and try to print what it display , then compare it in if condition.

 

 

Accept and hit Helpful if it helps.

Thank you,
Hemanth
Certified Technical Architect (CTA), ServiceNow MVP 2024, 2025

Siva Jyothi M
Mega Sage

Hi @Saurav Bhardwa2,

 

Try the below script.

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    if (newValue == 'Modify Existing') {
        g_form.showFieldMsg('type', 'Your existing access will be removed and the new access will be added.', 'info');
    }

}

Mark this answer as correct and helpful if it solves your issue.

 

Regards,

Siva Jyothi M.

Robin John
Kilo Sage

Seems like you are trying to use this script on the portal. Could you confirm if you have set the UI type =  ALL for your client script?

RobinJohn_0-1694175704098.png