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

AndersBGS
Tera Patron
Tera Patron

HI @Rajamouly , 

 

According to your script, you need to declear the variable "visible", so instead it should be:

 

(function executeRule(current, previous /*null when async*/) {
 var 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);

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.

 

best regards

Anders

If my answer has helped with your question, please mark my answer as the accepted solution and give a thumbs up.

Best regards
Anders

Rising star 2024
MVP 2025
linkedIn: https://www.linkedin.com/in/andersskovbjerg/

Hi @AndersBGS 

 

I declared the variable (it was not copied previously), even after i tried it is not working.

Ankur Bawiskar
Tera Patron
Tera Patron

@Rajamouly 

in query BR you don't have access to field value so you cannot determine if checkbox is checked or not

why not handle this using table 2 level READ ACL?

1 table level READ will be with Checkbox True condition

1 table level READ will be with Checkbox False condition

 

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

HI @Ankur Bawiskar 

 

Do i need to write any script inside ACL, i will give a try with ACL's