Script Include and UI Action Condition is Not working As expected

Rajesh Bandila
Tera Contributor

Hi,

 

I have created the UI action called "Required Action" on RITM table. now i want to make it this UI action available for only if logged In User is member of the RITM associated SC Task assignment group. I have tried by using below UI action Condition and Script Include but it is not working as expected. Please let me know, how to archive this by using UI action condition.

Please Find the below script for reference.
UI Action Condition:
new CheckUserGroup().isUserInRitmGroup(current.sys_id)

Script Include:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    isUserInRitmGroup: function() {
        var ritmSysId = this.getParameter('sysparm_ritm_sys_id');
        var ritmGrp = new GlideRecord('sc_req_item'); // RITM table
        if (ritmGrp.get(ritmSysId)) { // current RITM
            var taskGrp = new GlideRecord('sc_task'); // associated sc_task
            taskGrp.addQuery('request_item', ritmGrp.sys_id);
            taskGrp.query();
            if (taskGrp.next()) {
                var grp = new GlideRecord('sys_user_group'); // assignment group
                grp.get(taskGrp.assignment_group);
                return grp.hasMember(gs.getUserID()); // check if logged-in user is a member
            }
        }
        return false; // default to not visible
    },

    type: 'CheckUserGroup'
});

 

 

Thanks InAdvanced!!

1 ACCEPTED SOLUTION

briannice
Kilo Sage

Hi @Rajesh Bandila 

 

You do not need to create a client UI action. You can just provide the RITM record in the parameters of the function.

 

Condition:

new CheckUserGroup().isUserInRitmGroup(current);

Script:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = {
    initialize: function() {
    },

	isUserInRitmGroup: function(ritmGr) {
		var ritmId = ritmGr.getUniqueValue();

		var taskGr = new GlideRecord("sc_task");
		taskGr.addQuery('parent', ritmId);
		taskGr.query();

		while (taskGr.next()) {
			var userId = gs.getUserID();
			var groupId = taskGr.getValue("assignment_group");

			var groupMemberGr = new GlideRecord('sys_user_grmember');
			groupMemberGr.addQuery('user', userId);
			groupMemberGr.addQuery('group', taskId);
			groupMemberGr.query();

			if (groupMemberGr.next()) {
				return true;
			}
		}

		return false;
	},

    type: 'CheckUserGroup'
};

 

Let me know if this works.

 

Kind regards,

Brian 

View solution in original post

2 REPLIES 2

briannice
Kilo Sage

Hi @Rajesh Bandila 

 

You do not need to create a client UI action. You can just provide the RITM record in the parameters of the function.

 

Condition:

new CheckUserGroup().isUserInRitmGroup(current);

Script:

var CheckUserGroup = Class.create();
CheckUserGroup.prototype = {
    initialize: function() {
    },

	isUserInRitmGroup: function(ritmGr) {
		var ritmId = ritmGr.getUniqueValue();

		var taskGr = new GlideRecord("sc_task");
		taskGr.addQuery('parent', ritmId);
		taskGr.query();

		while (taskGr.next()) {
			var userId = gs.getUserID();
			var groupId = taskGr.getValue("assignment_group");

			var groupMemberGr = new GlideRecord('sys_user_grmember');
			groupMemberGr.addQuery('user', userId);
			groupMemberGr.addQuery('group', taskId);
			groupMemberGr.query();

			if (groupMemberGr.next()) {
				return true;
			}
		}

		return false;
	},

    type: 'CheckUserGroup'
};

 

Let me know if this works.

 

Kind regards,

Brian 

Hi @briannice 

 

Script working as expected. Thank you!!

 

Thanks,

Rajesh B