Onchange Client script State Value

muhammad4
Tera Contributor

 Hi I have this script onChange for planned start date, and one for end date as well pasted below which is working as I need it to. 
I'm kind of still learning javascript, so basically what I wanted to know when i first created the script I had the state value in quotes     if (state >= '-2'). This made the script run for change request in all states, but without quotes it works fine. Can you explain why, and why it just didn't give an error?
 

var state = g_form.getValue('state');
    if (state >= -2) {
        g_form.showFieldMsg('start_date', 'Please provide explanation for changing the planned start date in the notes');
        g_form.setMandatory('work_notes', true);

}


Thank you!

1 ACCEPTED SOLUTION

Pavankumar_1
Mega Patron

Hi,

if you give value on quotes it will take as a string but when you give without quotes it will take as an number and check all the state values as per that number will execute.

Hope you it helps you to understand.

Please Mark Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

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

View solution in original post

2 REPLIES 2

Pavankumar_1
Mega Patron

Hi,

if you give value on quotes it will take as a string but when you give without quotes it will take as an number and check all the state values as per that number will execute.

Hope you it helps you to understand.

Please Mark Correct/helpful if applicable, Thanks!! 

 

Regards

Pavankumar

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

Thank you!