onchange client script, oldValue is not coming in the alert.

Community Alums
Not applicable

Hi All,

Its a Yes/No catalog variable. I have written a onchange client script. The requirement is something like "if the particular field changes from Yes to No, do the logic". 

So i wrote like below, if (oldValue is Yes & newValue is No) but its not working. Even the alert in the 5th line is empty for oldValue, newValue alert is coming.

 

find_real_file.png

1 ACCEPTED SOLUTION

Hi,

then clear it only when the value selected is None

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading){
        return;
    }

    if(newValue == 'Yes'){
        g_form.setValue('hiddenVariable', 'Yes');
    }
    else if(newValue == ''){
        g_form.clearValue('hiddenVariable');
    }

    if(g_form.getValue('hiddenVariable') == 'Yes' && newValue == 'No'){
        // your logic
    }

}

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

18 REPLIES 18

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Can you explain this a bit more? Where are you using this exactly for example? Reading that it concerns a catalog variable, I'm wondering what your exact case is. For example is this on the Platform UI, where you want to change a variable on a submitted RITM?

If this is on a new Catalog Item in the Service Portal, this won't work, since there is no newValue.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Community Alums
Not applicable

No Mark, it should work. I just wrote an onchange client script for a varOne, to compare oldValue with newValue.

 

Like I asked, can you explain your case a bit more? Is this on an existing submitted RITM on the platform UI or service portal? Or is this on a new Catalog Item which you are about to submit?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020, 2021 ServiceNow Community MVP
2020, 2021 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Community Alums
Not applicable

My requirement is, i need to show an alert message only when variable value changes from "Yes to No".

Its a catalog item, when i try to raise a request in the service portal. I will be filling my form to submit a request. During that time i have a "yes/no" variable type, where i have to implement this logic only when value changes from Yes to No.

To achieve this i wrote an onchange client script to that variable. In onchange client script we can access oldValue & newValue parameters. That validation is not working here.