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

Urgent !!! CSM Query rule issue

manita1
Tera Expert

CSM Query rule not working as expected.

 

requirement 1: to show only those health cases for users that they opened , these users are basically members

requirment 2: To show cases to Managers opened by their department. 

ibhad read acls before on the case type table but customer wants user experience with CSM query rules where they don’t have to see security constraint message on the portal or workspace.

then I tried CSM query rules where, first one worked with on before business rule to only show users with cases opened by them but second one needs help. 
I want logged in user manager department and then query all cases for that department and only show those .

 

1 ACCEPTED SOLUTION

manita1
Tera Expert

I made this working by disabling OOB  query rules at parent table level ! 

View solution in original post

3 REPLIES 3

JackieZhang
Tera Contributor

I suggest to use before query instead of using CSM query rule. 

manita1
Tera Expert

I made this working by disabling OOB  query rules at parent table level ! 

briannice
Kilo Sage

Hello @manita1 

 

I had the following solution for this. In my example below I use a case type Health and Safety Case (sn_customerservice_hs_case) with the following requirements (I only provide the read configuration as the create/write/delete logic can just be created with normal ACLs or can be inherited from the out-of-the-box case table):

  • Only H&S agents can view these cases (sn_customerservice.hs_agent - custom role), normal CSM agents can not
  • Only consumers can view there own cases (sn_customerservice.consumer)

You should be able to extend this functionality to your custom needs.

 

Step 1: Case type table

 

The case type table has the H&S agent role linked to it. This is not really important, but I think it is clean.

 

briannice_2-1757971069781.png

 

Step 2: Create query rules

 

Query rule for H&S agents (with condition that is always true as the field is required and the agents can read all cases):

 

briannice_3-1757971222296.png

 

Query rule for consumers:

 

briannice_4-1757971314705.png

 

Step 3: Create table level read ACLs on case type which enforce query rules

 

ACL for H&S agents (with advanced script):

 

briannice_0-1757970868580.png

 

answer = false;
if(new global.CSMQueryRulesUtil().useQueryRules()) {
	var filter = new sn_queryrules.QueryRuleGenerator().getEncodedQuery("sn_customerservice_hs_case", "sn_customerservice.hs_agent");
	answer = GlideFilter.checkRecord(current,filter);
}

 

ACL for consumers (with advanced script):

 

briannice_1-1757970994489.png

 

answer = false;
if(new global.CSMQueryRulesUtil().useQueryRules()) {
	var filter = new sn_queryrules.QueryRuleGenerator().getEncodedQuery("sn_customerservice_hs_case", "sn_customerservice.consumer");
	answer = GlideFilter.checkRecord(current,filter);
}

 

Step 4: Update out-of-the-box BR which enforces query rules for cases

 

There is an out-of-the-box business rule called "Case query rules" which applies the CSM query rules to the case table as before query rules. In this business rule, query rules are applied based on the table of the current record. This business rule will run on the default case table, but also on case type tables (as they extend the default case table). This configuration will make sure that the default query rules will still work on the default case table and on any other case types for which you do not use custom query rules.

 

The change of this business rule is the only heavy customization in this setup (all other records are additions, not changing out-of-the-box records). But this should be fairly straightforward to catch any updates of this in a skipped record of an upgrade.

 

Find the script of the BR below, this is the only thing that has been changed.

 

(function executeRule(current, previous) {
	// List all tables which have custom query rules in an object.
	var customQueryRuleTables = {
		"sn_customerservice_hs_case": true
	};

	// Get the table name for which the query rules should be enforced.
	// If the table has custom query rules, use that table.
	// Otherwise use the default case table.
	var currentTable = current.getTableName();
	var queryTable = customQueryRuleTables[currentTable] ? currentTable : "sn_customerservice_case";

	// Create the encoded query.
	var currentQuery = current.getEncodedQuery();
    var query = new sn_queryrules.QueryRuleGenerator().appendEncodedQuery(queryTable, currentQuery);

	// Add the encoded query
    current.addEncodedQuery(query);
})(current, previous);

 

 

Hopefully this helps!

 

Kind regards,

Brian