If loggedin user is not member in the group then info message to select in Assign to

chanikya
Tera Guru

If logged in User is not a member in Assignment group then popup " logged in user not member in that group"

upto this script working fine, at the same time, i would like to popup message" select in Assign to", in case if assign to is not empty then change State=2,

 

UI Action:   chceked:Client,         Onclick: onClicking     // Script is not working 

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');
if(gr.assigned_toISNOTEMPTY)
{
g_form.setValue('state',2);
}
else
{
g_form.addInfoMessage('selct in assign to');
}
}
}

1 ACCEPTED SOLUTION

Unchecked Client Checkbox and try with below code:

if(gs.getUser().isMemberOf(current.assignment_group))
 {
 current.assigned_to=gs.getUserID();
 current.state=2;
	 
 }

 else
 {
  if(current.assigned_to!='')
  {
    current.state=2;
  }
 else
 {
	gs.addInfoMessage('Looged-in user is not a member of the selected Assignment Group');
 	gs.addInfoMessage('select in assign to');
 }
 }

action.setRedirectURL(current);
current.update();

 

 

View solution in original post

22 REPLIES 22

Sagar Patro
Kilo Guru

Chanikya,

May I ask, what are you trying to achieve. Let me know if I am correct on the idea or not.

On selection of an assignment group, if the logged in user is part of the group, then select the logged in user as assigned to or else show a message "logged in user, not in the group."

Is that right? If yes, then you do not need a UI action!

i have button "Assign Incident"

if logged in user is an member in Assignment group"then Assign to filled with logged in user name and state=2

OR

if logged in user is NOT an member in Assignment group"then show message " Loggedin user is not member in assignment group  and Select user in Assign To" 

after i selected user manually  in Assign to field then changed to  State=2.......

 

Got it.

This should do it.

function onClicking()
{
alert(g_user.userID);
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);
	g_form.setValue("state",2);//set the value here
	}
else
	{
		g_form.showFieldMsg('assigned_to','Looged-in user is not a member of the selected Assignment Group');
		//gr.assigned_to does not exist!!!
		
		/*if(gr.assigned_toISNOTEMPTY)
		{
		g_form.setValue('state',2);
		}
		else
		{
		g_form.addInfoMessage('selct in assign to');
		}*/
		
	}

//handle the message and state
if(g_form.assigned_to != "")
		{
		g_form.setValue('state',2);
		g_form.hideFieldMsg("assigned_to");
		}
		
}

Tushar Sharma2
Kilo Guru

Hello,

Could you please check with code.

if(gs.getUser().isMemberOf(g_form.getValue(assignment_group)))
{
g_form.setValue('assigned_to',g_user.userID);
g_form.setValue('state',2);
}

else
{
 g_form.addInfoMessage('Logged-in user is not a member of the selected Assignment Group');

}

Hit Like or Correct on the impact of response.

-Tushar