Why is this so difficult? Creating an alert to show when a caller is a member of a particular group.

JennyBell
Tera Contributor

I have run this scenario in the community, Google and Copilot multiple ways and there are so many different ways this can be done I'm getting confused because each one I try does not work.  Can someone provide a script to do the following:  

 

When a name is entered into the caller id field on the Incident form, check if the caller id is a member of a group.


Caller_ID:  Jen Nocode

Group: Pilot_Participant

If, yes Jen Nocode is a member of the Pilot Participant group = show an alert telling the call taker the user is a pilot participant

 

If No, no alert needed

 

Some solutions provided had me create a Business Rule and a Client Script, some had just a Client Script.

 

Thanks!

 

 

 

 

6 REPLIES 6

Bhuvan
Kilo Patron

@JennyBell 

 

You cannot validate server-side functions directly from client script. You need to first create script include function that is client callable and create a client script to call the script include.

 

Below is a reference,

 

https://www.servicenow.com/community/developer-blog/how-to-check-if-loggedin-user-is-part-of-group-f...

 

You can finetune for your requirements and it should work.

 

Script Include

var CheckmemberOf = Class.create();
CheckmemberOf.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    checkGroupMember: function() {
        var grp = this.getParameter('sysparm_grp');
        return gs.getUser().isMemberOf(grp);
    },
    type: 'CheckmemberOf'
});

Client Script

function onLoad() {
    var ga = new GlideAjax('CheckmemberOf');
    ga.addParam('sysparm_name', 'checkGroupMember');
    ga.addParam('sysparm_grp', 'group sys_id');
    ga.getXML(checkGroup);
}

function checkGroup(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer == 'true') {
        alert('User is a Pilot Participant');
    } 
}

 

If this helped to answer your query, please mark it helpful & accept the solution. 

 

Thanks,

Bhuvan

@JennyBell 

 

Did you get a chance to review this as I believe provided information would fulfill your requirements.

 

As per community guidelines, you can accept more than one answer as accepted solution. If my response helped to answer your query, please mark it helpful & accept the solution.

 

Thanks,

Bhuvan