if logged in user is not a member in that group

chanikya
Tera Guru

Ui Action: Assign me

if(gs.getUser().isMemberOf(current.assignment_group));
{

current.assigned_to = gs.getUserID();
}

 

if he  is not a member in that group then popup message 

1 ACCEPTED SOLUTION

Archana Reddy2
Tera Guru

Hi,

Try using the below script in UI Action with Client field checked.

Onclick: onClicking()

function onClicking()
{
	var gr = new GlideRecord('sys_user_grmember');
	gr.addQuery('user',g_user.userID);
	gr.addQuery('group',g_form.getValue('assignment_group'));
	gr.query();
	if(gr.next())
		{
			g_form.setValue('assigned_to',g_user.userID);
		}
	else
		{
			g_form.addInfoMessage('Looged-in user is not a member of the selected Assignment Group');
		}
}

Hope this helps.

Thanks,

Archana

View solution in original post

11 REPLIES 11

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Ahh ok. If this is in a business rule you need the stub code from the business rule as well, but your code needs to be formatted like this without the semicolon at the end of the if statement.

(function executeRule(current, previous /*null when async*/) {
	
	if(gs.getUser().isMemberOf(current.assignment_group)) {
		current.assigned_to = gs.getUserID();
	}
	else {
		gs.addInfoMessage("not mamber");
	}
	
})(current, previous);

 

Name is not populated in Assigned To field , i have used ur script  , As well Admin  is one of the member if CAB group, but name is not populated, y? when i clicked on UI action: TEST

find_real_file.png

Brad Tilton
ServiceNow Employee
ServiceNow Employee

If this is a ui action, try just doing this:

 

	if(gs.getUser().isMemberOf(current.assignment_group)) {
		current.assigned_to = gs.getUserID();
	}
	else {
		gs.addInfoMessage("not mamber");
	}

Archana Reddy2
Tera Guru

Hi,

Try using the below script in UI Action with Client field checked.

Onclick: onClicking()

function onClicking()
{
	var gr = new GlideRecord('sys_user_grmember');
	gr.addQuery('user',g_user.userID);
	gr.addQuery('group',g_form.getValue('assignment_group'));
	gr.query();
	if(gr.next())
		{
			g_form.setValue('assigned_to',g_user.userID);
		}
	else
		{
			g_form.addInfoMessage('Looged-in user is not a member of the selected Assignment Group');
		}
}

Hope this helps.

Thanks,

Archana

Thanks Archana!

 it is working fine....great