Client Script to run only for the first selection
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:20 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:29 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:33 AM
I thought of using something like if oldValue == '' but when you load the form oldValue is basically undefined.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:36 AM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-08-2024 12:31 AM
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