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

Please help with Business Rule Script conditions.

Annie10
Tera Contributor

Hello,

Could someone please help review the code? It is not working. The purpose of the business rule is to allow users to see records that are assigned to their team, but not records assigned to other teams. Thank you.

 

When to Run:  Before, Query

Annie10_0-1715995405484.png

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

if (!gs.hasRole("itil") && gs.getSession().isInteractive()) {
        var u = gs.getUserID();
        var qc = current.addQuery("requested_for", u).addOrCondition("opened_by", u).addOrCondition("watch_list", "CONTAINS", u).addOrCondition('assignment_group', '927934e41b6bf0104425cb35624bcbe9');
        gs.info("query restricted to user: " + u);
		current.addQuery('assignment_group', '927934e41b6bf0104425cb35624bcbe9');
    }

})(current, previous);

 

26 REPLIES 26

Community Alums
Not applicable

@Annie10 ,

 

You need to add the code at the last of the 1st line. Plz check the srn shot.

 

OR

 

You can remove the existing code & paste the below code.

 

current.isNewRecord() || current.request.opened_by == gs.getUserID() || current.opened_by == gs.getUserID() || current.request.requested_for == gs.getUserID() || current.requested_for == gs.getUserID() || gs.hasRole('itil,sn_request_write') || gs.getUser().isMemberOf(current.assignment_group);
 
I started answering community questions recently. If my answer helped you in any way, please mark it as helpful or correct. It would be a great boost.

AndersBGS
Tera Patron
Tera Patron

Hi @Annie10 ,

 

Why utilize a business rule and not a data filtration rule?

 

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 

That is because the Business Rule is the only method I am familiar with. I had never heard of a data filtration rule, but I gave it a try after hearing about it from you. However, when using Data Filtration Records to display only the records assigned to the Database group if you are a member of that group, it does not seem to be working.  

 

1. Abel Tuter belong to 1 group "Database"

2. When I impersonated Abel Tuter, I should only see the Database records. However, I was able to see all records.

Annie10_1-1716186950274.png

 

 

 

What have I done wrong with the Data Filtrations? 

 

 

Annie10_0-1716185089096.png

 

Hi @Annie10 ,

 

That is also correct. The data filtration rule will list which records specific users can see based on condition. So according to your screenshot, Abel (as part of database group), will be able to see database records.... people not part of the database assignment group will not be able to see the database records. 

 

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/

Hello @AndersBGS 

Upon reevaluation of the screenshot, it's apparent that the data retrieved for Abel contains entries from a group he isn't a part of. There seems to be a misconfiguration in the data filtration process.  Here are the same screenshots I posted earlier.  Thank you

Annie10_0-1716312690108.png

Annie10_1-1716312936670.png