Populate the field info message it's checking the user in that particular group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 05:30 AM
Hi all,
There is one requirement, in that incident form , when the caller field user is the "Testing" group then field message should be populated under subcategory field. I have created the onchange script but it's showing some error in the form,
var InvestigationGroup = '12334567895'; //sys id of the group
var userGR = new GlideRecord('sys_user_grmember');
userGR.addQuery('user', caller);
userGR.addQuery('group',InvestigationGroup);
userGR.query();
if(userGR.next())
{
g_form.showFieldMsg('subcategory','testing', false);
}
getting the below error
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 05:35 AM
Hi @DeepikaR1661877 ,
GlideRecord is a server side function and onChange client script is client side, on client script you can use
g_user.hasRole('InvestmentGroup');
You can read the documentation:
https://developer.servicenow.com/dev.do#!/reference/api/xanadu/client/c_GlideUserAPI#r_GlideUser-has...
If you want a more complex solution you will need to create a script include callable on client side.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-31-2025 05:49 AM
using GlideRecord is not recommended in client side
you can use GlideRecord with callback
var gr = new GlideRecord("sys_user_grmember");
gr.addQuery("user", g_form.getValue('caller_id'));
gr.addQuery("group.name", "Testing"); // give group name
gr.query(checkRecord);
function checkRecord(gr) {
if (gr.next()) {
g_form.showFieldMsg('subcategory', 'testing', 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
‎02-02-2025 05:28 AM
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