The CreatorCon Call for Content is officially open! Get started here.

Business rule to check the updated by is member of assignment group

Twinkle S
Mega Sage
Mega Sage

I have a requirement to make a custom field Respond set to true if the updated by is the member of current assignment group.Everything works fine except the if condition, if condition is not fulfilling.  Below is the code for After update 

 

(function executeRule(current, previous /*null when async*/) {

var a=current.sys_updated_by;
var b=current.assignment_group;
var c=gs.getUser();
gs.addInfoMessage(b);
gs.addInfoMessage(a);
if(current.sys_updated_by.isMemberOf(current.assignment_group))
{
gs.addInfoMessage('inside if loop');
current.u_responed=true;

}

 

Regards

Twinkle

11 REPLIES 11

Twinkle S
Mega Sage
Mega Sage

Hello all,

I dont want to check the getUser . I need to check updated by. Also, the setworkflow() will only work only if the codition is matched. The if condition itself is not fulfilling

Try this code now:

var a=current.sys_updated_by;
var b=current.assignment_group;
var c=gs.getUserID();
gs.addInfoMessage(b);
gs.addInfoMessage(a);
if(a.isMemberOf(current.assignment_group))
{
gs.addInfoMessage('inside if loop');
current.u_responed=true;

current.setWorkflow(false);

current.udpate();

}

Thank you,
Abhishek Gardade

Harsh Vardhan
Giga Patron

try now. 

 

(function executeRule(current, previous /*null when async*/) {

var a=current.sys_updated_by; // this field return the user_id so you have to glide record here to get the sysid.

var gr = new GlideRecord('sys_user');

gr.addQuery('user_name',a);

gr.query();

if(gr.next()){

var res = gr.sys_id;


var b=current.assignment_group;
var c=gs.getUserID();
gs.addInfoMessage(b);
gs.addInfoMessage(a);
if(res.isMemberOf(current.assignment_group))
{
gs.addInfoMessage('inside if loop');
current.u_responed=true;

}

}

Nope. Not happening.Its not going inside the if loop

can you put some log and validate it. 

 


var a=current.sys_updated_by; 

gs.log('Updated By is'+ a);

var gr = new GlideRecord('sys_user');

gr.addQuery('user_name',a);

gr.query();
gs.log('Row Count+ gr.getRowCount());
if(gr.next()){

var res = gr.sys_id;


var b=current.assignment_group;
var c=gs.getUserID();
gs.addInfoMessage(b);
gs.addInfoMessage(a);
if(res.isMemberOf(current.assignment_group))
{
gs.log('Comimng inside if block ');
gs.addInfoMessage('inside if loop');
current.u_responed=true;

}

}