what is the code to check if the current logged in user is group member of current assignment group of the incident through on load client script

VIKAS MISHRA
Tera Contributor

i know that on business Rule we use code if (gs.getUser().isMemberOf('Database Application Support')) {}

However do not know how to chekc the same thorugh on load client script.

1 ACCEPTED SOLUTION

Arkesh Kumar
Giga Guru

Hi,

 

Create a Business rules as below:

Display Query Business rules

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

g_scratchpad.grp = gs.getUser().isMemberOf('sys_id of the group');
g_scratchpad.usrid = gs.getUserID(); // gets current logged in user
})(current, previous);

 

Then Create Client script

if((g_scratchpad.grp.toString() == 'true'))
{
//script you want to execute
}

 

Thank You,

Arkesh

View solution in original post

4 REPLIES 4

Arkesh Kumar
Giga Guru

Hi,

 

Create a Business rules as below:

Display Query Business rules

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

g_scratchpad.grp = gs.getUser().isMemberOf('sys_id of the group');
g_scratchpad.usrid = gs.getUserID(); // gets current logged in user
})(current, previous);

 

Then Create Client script

if((g_scratchpad.grp.toString() == 'true'))
{
//script you want to execute
}

 

Thank You,

Arkesh

@VIKAS MISHRA 

 

If My Answer helps. Make my answer as Correct answer / Helpful

 

Thank You,

Arkesh

Akanksha Gupta2
Mega Guru

Hi Vikas ,

I have done this but by using onChange Client script and business rule.

One Important point is here , first ypu add current logged in user in your group and then do testing .

PFB code :-

Script Include :-

var MemberofAssignmentGroupCS = Class.create();
MemberofAssignmentGroupCS.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    assing: function() {
        var g = this.getParameter('sysparm_group');
		gs.addErrorMessage(g);
        if (gs.getUser().isMemberOf(g)) {
            return true;
        } else {
            return false;
        }
    },
    type: 'MemberofAssignmentGroupCS'
});

Client Script(Assignment group)

unction onChange(control, oldValue, newValue, isLoading, isTemplate) {
    if (isLoading || newValue === '') {
        return;
    }

    var ga = new GlideAjax('MemberofAssignmentGroupCS');
    ga.addParam('sysparm_name', 'assing');
    ga.addParam('sysparm_group', g_form.getValue('assignment_group'));
    ga.getXML(memberOfAssignee);

    function memberOfAssignee(response) {
        var ans = response.responseXML.documentElement.getAttribute('answer');
		alert(ans);
        if (ans == 'true') {
            g_form.setReadOnly('short_description', true);
        } else {
            g_form.setReadOnly('short_description', false);
        }
    }
}

Pls mark me correct or helpful

Thanks , 

Akanksha

 

Hi,

 

There is no need of Script Include / Ajax to call to determine the group, logged in user belongs to.

We can do it through Business rules and client script using g_scratchpad which is a simple way to determine.

Thank you,

Arkesh