Client Script to run only for the first selection

Dawid2
Giga Guru

Hello,

I have a variable on my form called "Type". It is a select box with 2 choices (A and B) and None. What I'm looking after is to create catalog client script that will show a popup only if user selects the Type for the first time. How can it be achieved?

Example:

1. User opens a form and selects Type from None to A - popup should be visible

2. User opens a form and selects Type from None to B - popup should be visible

3. User opens a form, selects Type from None to A - popup should be visible, but then selects Type from A to B (or none) - popup should no longer be visible.

 

I got the popup to populate but it shows every time user changes the Type variable.

4 REPLIES 4

Prince Arora
Tera Sage
Tera Sage

@Dawid2 

 

You can play with the "oldValue" or "newValue" parameters available in client script as below

 

if(oldValue == "" && newValue!=""){
   //show your popup
}

 

 

//suppose you have selected from none to something, in that case oldValue would be empty and newValue contains the data, next time you have selected from A->B, then oldValue will be "A"(not empty) and newValue contains B

 

If my answer solved your issue, please mark my answer as  Correct & 👍Helpful based on the Impact.

 

I thought of using something like if oldValue == '' but when you load the form oldValue is basically undefined.

oldValue won't help you here, since there is no oldValue.

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn

Mark Roethof
Tera Patron
Tera Patron

Hi there,

 

I don't think something with newValue would work. Unfortunately you also don't have a scratchpad or something 🙂 Perhaps adding a non-visible checkbox variable could help? I'll brainstorm a bit. 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

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

LinkedIn