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

How to restrict access via Before Query Business Rule?

SNOW Developer6
Tera Contributor

Hi,

I am working on Before Query Business Rule.

I want to show the requested_for records to  requested_for user who is logged in.

 

I have written the following code but its not working.I am only getting blank page.

 

Can u please look at it ?

 

(function ExecuteRule(current,previous)
{   
         if(gs.hasRole('myrole') && gs.getSession().isInteractive())
{
           current.addQuery('requested_for','==',gs.getUserID());
}

})(current,previous);

 

I dont know why its not working.

1 ACCEPTED SOLUTION

Cris P
Tera Guru

Hello, please try as below (remove the '==')

(function ExecuteRule(current,previous){   
         if(gs.hasRole('myrole') && gs.getSession().isInteractive()){
           current.addQuery('requested_for', gs.getUserID());
}
})(current,previous);

View solution in original post

7 REPLIES 7

Cris P
Tera Guru

Hello, please try as below (remove the '==')

(function ExecuteRule(current,previous){   
         if(gs.hasRole('myrole') && gs.getSession().isInteractive()){
           current.addQuery('requested_for', gs.getUserID());
}
})(current,previous);

Musab Rasheed
Tera Sage

Hello,

It should be single '=' not '=='

This worked for me

current.addQuery('requested_for','=',gs.getUserID());

Regards

Please hit like and mark my response as correct if that helps
Regards,
Musab

Muhammad Khan
Mega Sage

Hi,

 

It would be better if you utilize the condition field of Business Rule, so that it will only be executed when condition is met. See the below image for reference.

find_real_file.png

SNOW Developer6
Tera Contributor

Thank you so much for your answer.

 

Its working now.

I want the admin to view all the records.

I tried this but I am getting blank page for the admin role.What should I do for the admin.

(function ExecuteRule(current,previous){   
         if(gs.hasRole('admin') && gs.getSession().isInteractive()){
         current.query();
}
})(current,previous);