- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 02:53 AM
Hi All,
There is one requirement in incident table when category is "Dev" and subcategory is "Test" then i want populate the info message under the subcategory field(Based upon the subcategory is depend field of category) So i have created the one onchange client script, it's not working i have try to get the value by using the console, even i didn't get, any one help on this part?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:37 PM
Hello @DeepikaR1661877
- No, You cannot populate link using g_form.showfieldmsg().
- The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 03:36 AM - edited 01-22-2025 03:51 AM
Write this script on onChange client script on subcategory field .
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || isTemplate) {
return;
}
var category = g_form.getValue('category');
if (category == 'Dev' && newValue == 'Test') {
g_form.showFieldMsg('subcategory', 'This is a Test subcategory for Development', 'info');
} else {
g_form.hideFieldMsg('subcategory');
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 03:49 AM
Your script has an issue.
You should use == and not === during comparision
Also are you sure you are comparing the correct values for category and subcategory?
If yes then your script will work fine.
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-26-2025 10:21 PM
Hi @Ankur Bawiskar ,
I have one more doubt, can populated the link by using g_form.showfieldmsg ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:37 PM
Hello @DeepikaR1661877
- No, You cannot populate link using g_form.showfieldmsg().
- The g_form.showFieldMsg() method is primarily used to display messages (such as error, warning, or informational messages) below a field.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-22-2025 04:11 AM - edited 01-22-2025 04:52 AM
Hello @DeepikaR1661877
Try this onChange Client script:
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
// Avoid executing script during form load or if newValue is empty
if (isLoading || newValue === '') {
return;
}
g_form.hideFieldMsg('subcategory');
// Get values of category and subcategory fields
var subcategory = newValue; // Subcategory field's new value
alert('Subcategory: ' + subcategory); // Debugging
var category = g_form.getValue('category'); // Parent field
alert('Category: ' + category); // Debugging
// Check if category is 'Dev' and subcategory is 'Test'
if (category === 'dev' && subcategory === 'test') { //update 'test' and 'dev' to backend value
g_form.showFieldMsg('subcategory','Please proceed with caution while handling internal support investigations','info');
}
}
Note: Please update 'dev' and 'test' to the backend value of 'Dev' and 'Test' in script.
To get the backend value:
- Right click on form label(Category/Subcategory)
- Configure dictionary
- Under related list -> choice section the value column holds the backend name.
Hope this helps!
"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"
Thank You
Juhi Poddar