Restrict "Assigned to" changes to only group members.

gracjan
Tera Guru

So the goal is to permit only group members to "assigned to" tasks among themselves and not the customer. For instance, when a group is assigned and if a user is not part of the assignment group, they get read-only field for "Assigned to", when the user who access the form is part of the group they get the choice to pick the group member. Please help.

 

sn.PNG

1 ACCEPTED SOLUTION

Ok. I am answering my own question. I tried dark megic and it worked.

This is script include:

var UserInfo4 = Class.create();
UserInfo4.prototype = Object.extendsObject(AbstractAjaxProcessor, {
isUserInGroup: function() {
var user_id = this.getParameter('sysparm_user_id');
var group_id = this.getParameter('sysparam_group_id');

var grUser = new GlideRecord('sys_user_grmember');
grUser.addQuery('user', user_id);
grUser.addQuery('group', group_id);
grUser.query();
if (grUser.next()) {
return "true";
}
return 'false';
},
type: 'UserInfo4'
});

This is OnChange client script:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
var user_id = g_user.userID;

   var ajax = new GlideAjax('UserInfo4');
    ajax.addParam('sysparm_name', 'isUserInGroup');
    ajax.addParam('sysparm_user_id', user_id);
    ajax.addParam('sysparam_group_id', newValue);
    ajax.getXML(setisUserInGroup);
        
 	function setisUserInGroup(response) {
 		var answer = response.responseXML.documentElement.getAttribute('answer');
		//alert(answer);
 	if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);														  
   }
    }
	
	
}

This is onLoad:

function onLoad() {
   //Type appropriate comment here, and begin script below
	//alert(g_scratchpad.grp);
	
	
var user_id = g_user.userID;
	var group_id = g_form.getValue('assignment_group')

   var ajax = new GlideAjax('UserInfo4');
    ajax.addParam('sysparm_name', 'isUserInGroup');
    ajax.addParam('sysparm_user_id', user_id);
    ajax.addParam('sysparam_group_id', group_id);
    ajax.getXML(setisUserInGroup);
        
 	function setisUserInGroup(response) {
 		var answer = response.responseXML.documentElement.getAttribute('answer');
		//alert(answer);
 	if(answer == "true"){g_form.setReadOnly('assigned_to', false);}else{g_form.setReadOnly('assigned_to', true);														  
   }
    }
}

View solution in original post

6 REPLIES 6

Just out of curiosity is there a reason why you did not just use an ACL for this?

 

Sure Sir. I tried the ACL rule but I am always hesitant to mess with ACL. On the other hand, we use domain separation and scripts may be more manageable than ACL. At this point, my safest path was script but this may change. Thank you.