- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 12:19 AM
Hi All,
Please help me and thanks in advance.
The requirement is on change of yes or no variable, the code that is entered on another variable needs to be validated.
ie. If yes is selected for choice the code variable needs to have a k in the entered code. This is required
Below is the script that I tried.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2025 12:28 AM
try this
It's yes no variable so it won't give true/false value
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'yes') {
var Code = g_form.getValue('code');
if (Code.indexOf('k') > -1) {
g_form.hideFieldMsg('code');
} else {
var msg = 'code must contain an "k"';
g_form.showFieldMsg('code', msg, 'error');
g_form.clearValue('code');
}
} else {
g_form.hideFieldMsg('code');
}
}
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
01-23-2025 12:28 AM
try this
It's yes no variable so it won't give true/false value
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
if (newValue == 'yes') {
var Code = g_form.getValue('code');
if (Code.indexOf('k') > -1) {
g_form.hideFieldMsg('code');
} else {
var msg = 'code must contain an "k"';
g_form.showFieldMsg('code', msg, 'error');
g_form.clearValue('code');
}
} else {
g_form.hideFieldMsg('code');
}
}
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
01-23-2025 12:33 AM
@satya30
As you saying its yes no variable why you are checking true false value. First try to see what value is coming in newvalue when options are selected and on basis of that proceed with your logic.
If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.
Thanks & Regards
Viraj Hudlikar.