Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

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

chanikya
Kilo Sage

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

Hi ,

My script is Working now....

but how can i save it

 

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);
g_form.setValue('state',2);
}
else
{
var gg= g_form.getValue('assigned_to');
if(gg!='')
{
g_form.setValue('state',2);
}
else
{
g_form.addInfoMessage('Looged-in user is not a member of the selected Assignment Group');


g_form.addInfoMessage('selct in assign to');
}
}
}

At the end write below

 

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

But Guys ServiceNow do not recommended to Glide the records in Client Script, it will impact on your performance.

i request you , can you please suggest me in Server side script...

not saved .....

 

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);
g_form.setValue('state',2);
}
else
{
var gg= g_form.getValue('assigned_to');
if(gg!='')
{
g_form.setValue('state',2);
}
else
{
g_form.addInfoMessage('Looged-in user is not a member of the selected Assignment Group');
g_form.addInfoMessage('selct in assign to');
}
}
action.setRedirectURL(current);
current.update();
}