Populate the field info message it's checking the user in that particular group

DeepikaR1661877
Tera Contributor

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

DeepikaR1661877_0-1738330244171.png

 

3 REPLIES 3

Marco0o1
Tera Sage

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.

 

Ankur Bawiskar
Tera Patron

@DeepikaR1661877 

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.

@DeepikaR1661877 

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.