Before Query Business Rule is not working

Rajamouly
Tera Expert

HI,

 

I am trying to restrict the incident records, when the user is tick on the check box  'Visible to HRIS team' and should be part of any of two assignment groups  "HRIS - Workday Support"  and "HRIS - iCIMS Support" .

 

Below is the Business Rule Written but it is not working.

 

(function executeRule(current, previous /*null when async*/) {
 visible= current.u_visible_to_hris_team;
  if(visible=='true'){  
    if(gs.getUser().isMemberOf('HRIS - Workday Support')) {
current.addQuery('assignment_group.name','HRIS - Workday Support');
}
    else if (gs.getUser().isMemberOf('HRIS - iCIMS Support')){
current.addQuery('assignment_group.name','HRIS - iCIMS Support');
}
}   
})(current, previous);
 
Note: The Business Rule is working if we remove the Check box condition "if(visible=='true')" ,  Please help me how should it make it work for Check box True condition.
11 REPLIES 11

@Rajamouly 

just with conditions it will work

Ensure you give correct conditions for both

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

HI @Ankur Bawiskar 

 

I crated a custom role 'HRIS_WD' same role i have assigned to two HRIS groups, created a new Read ACL on incident table with condition 'Visible to HRIS Team is True'  and if i logged in with HRIS user and tick the check box true, same INC is visible to all other ITIL users.

 

Rajamouly_0-1688731206010.png

 

Please advise anything i am missing?

@Rajamouly 

your query BR and table level READ ACL should be in sync

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

HI @Ankur Bawiskar 

 

Sorry to trouble you again, i have enabled both BR and ACL but still no luck.

I removed the condition  if(visible=='true')  from BR, below is the BR script

 

(function executeRule(current, previous /*null when async*/) {
if(gs.getUser().isMemberOf('HRIS - Workday Support')) {
current.addQuery('assignment_group.name','HRIS - Workday Support');
}
    else if (gs.getUser().isMemberOf('HRIS - iCIMS Support')) {
current.addQuery('assignment_group.name','HRIS - iCIMS Support');
}
    
})(current, previous);

 

Amit Gujarathi
Giga Sage
Giga Sage

HI @Rajamouly ,
I trust you are doing great.
Please refer below updated code:

(function executeRule(current, previous /*null when async*/) {
  var visible = current.u_visible_to_hris_team;
  if (visible === 'true') {
    var assignmentGroup = current.assignment_group;
    if (assignmentGroup.nil()) {
      current.addQuery('assignment_group.nameIN', ['HRIS - Workday Support', 'HRIS - iCIMS Support']);
    } else {
      var assignmentGroupName = assignmentGroup.name.toString();
      if (assignmentGroupName !== 'HRIS - Workday Support' && assignmentGroupName !== 'HRIS - iCIMS Support') {
        current.addQuery('assignment_group.nameIN', ['HRIS - Workday Support', 'HRIS - iCIMS Support']);
      }
    }
  }
})(current, previous);

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi