- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 02:55 AM
Hello Community!
I have an urgent issue that I need to solve.
I created the following client script at catalog item level and it works fine.
However, my users are in the need to add multiple rows, so I created a variable set and included the script in there, but it doesn't work anymore.
Any idea why an onChange value doesn't work in variable set ? Should I do it differently ?
See my code :
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
// Clear any previous messages
g_form.hideFieldMsg('line_number_2');
var lineNumber = g_form.getValue('line_number_2');
if (lineNumber.indexOf('/OOB') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Out of Band", 'info', false);
} else if (lineNumber.indexOf('/B') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 100 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/C') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 1.000 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/D') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 10.000 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/E') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Dark Fiber", 'info', false);
} else if (lineNumber.indexOf('/F') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 200 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/G') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 500 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/H') > -1 ) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 2.000 Mbits/S", 'info', false);
} else {
g_form.showFieldMsg('line_number_2', 'Type of the line is not specified yet', 'info', false);
}
}
Thanks
Jérôme
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:18 AM
nope, I am referring create a fresh variable within that MRVS and deactivate the line_number_2
Then create fresh client script on that new variable and then see
Did the alert come?
Remember the onChange will run only when you type the details in variable and you click elsewhere on that modal, it won't trigger as and when you type.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 04:56 AM
did you try adding alert and see if that onchange is triggering?
Try creating a fresh single line text variable and then add the client script on it, disable the one which you already created
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
alert('inside onchange');
// Clear any previous messages
g_form.hideFieldMsg('line_number_2');
var lineNumber = g_form.getValue('line_number_2');
if (lineNumber.indexOf('/OOB') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Out of Band", 'info', false);
} else if (lineNumber.indexOf('/B') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 100 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/C') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 1.000 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/D') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 10.000 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/E') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Dark Fiber", 'info', false);
} else if (lineNumber.indexOf('/F') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 200 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/G') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 500 Mbits/S", 'info', false);
} else if (lineNumber.indexOf('/H') > -1) {
g_form.showFieldMsg('line_number_2', "This line is of type Ethernet 2.000 Mbits/S", 'info', false);
} else {
g_form.showFieldMsg('line_number_2', 'Type of the line is not specified yet', 'info', false);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:15 AM
Hey @Ankur Bawiskar
I tried already in a fresh field in a catalog variable and it was working perfectly.
I have the need to run this in the variable set, and there, it stopped working.
When I load the form however, it sets the last if value to Type of the line is not specified yet, it seems that only OnChange is not working in the variable set.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:18 AM
nope, I am referring create a fresh variable within that MRVS and deactivate the line_number_2
Then create fresh client script on that new variable and then see
Did the alert come?
Remember the onChange will run only when you type the details in variable and you click elsewhere on that modal, it won't trigger as and when you type.
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 08:03 PM
Hope you are doing good.
Did my reply answer your question?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-21-2025 01:15 AM
Thanks man! It works fine. 🙂