If logged in user is member of current assignment group then populate the alert message

vinuth v
Tera Expert

Hi All,

 

I need to populate the alert message when If logged in user is member of current assignment group.

For this I tried with the display business rule and client script,

Display business rule:

(function executeRule(current, previous /*null when async*/) {

    // Add your code here
    g_scratchpad.sd=gs.getUser().isMemberOf(current.assignment_group);

})(current, previous);
 
Client script:
Table is incident and Type is onLoad,
function onLoad() {
   
   if(g_scratchpad.sd==true){
   alert("User is group member");
 
   }
}
But it's not working as expected.
 
Thanks in advance,
Vinuth
6 REPLIES 6

Priyankagupta
Giga Guru

 

@vinuth v,

Are you aiming to display an alert message when the logged-in user is an incident assignment group member? If so, try this approach. 

 

Display Business Rule:

(function executeRule(current, previous /*null when async*/ ) {
    if (current.assignment_group) {
        var userIsMember = gs.getUser().isMemberOf(current.assignment_group.toString());
        g_scratchpad.isGroupMember = userIsMember;
    }
})(current, previous);


OnLoad Client Script :

function onLoad() {
    if (g_scratchpad.isGroupMember) {
        alert("You are a member of the assignment group for this incident.");
    } else {
        alert("You are not a member of the assignment group for this incident.");
    }
}

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

 

Thanks & Regards,

Priyanka Gupta

Sumanth16
Kilo Patron

Hi @vinuth v ,

 

Please try below script:

 

1. Create Script Include

Name : CheckmemberOf

Make Sure Client Callable is checked to true.

 

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

 

 2. Use above script include from client side script. 

 

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

function checkGroup(response) {
    var answer = response.responseXML.documentElement.getAttribute("answer");
    if (answer == 'true') {
        alert('Logged in User is part of group');
    } 
}

 

Hope this helps. Please mark the answer as correct/helpful based on impact.

 

Thanks &Regards,

Sumanth Meda