Query Business rule for records from an extended table.

M_iA
Kilo Sage

Hi, was wondering if someone could assit?

Case table - sn_customerservice_case

We have an extended table called managed service case - sn_customerservice_managed_service_case

I want to create a rule that allows a specific roled user to see all cases created directly on the case table. But only certain cases raised on the sn_customerservice_managed_service_case table.

The parameters on the extended table are as follows:

our customer_account table records have a reference field linked to a security group.

So the BR script needs to look at these cases and if a security group linked to the record, check to see whether the current user is in the group and if so, allow them to view.

 

I have tried creating this using the script below, but it not working as I had hoped when looking at the sn_customerservice_case table. It shows all cases created on the sn_customerservice_case table, but also all cases created on the extended table.

 

Please could someone point out what I am doing wrong?

 

M_iA_0-1665659661257.png

 

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

    if (current.getTableName() == 'sn_customerservice_managed_service_case') {

        var result = "";
        var currentUser = gs.getUser();

        var rec = new GlideRecord('customer_account');
        rec.addNotNullQuery('u_access_container_group');
        //rec.addQuery('u_managed_services',true);
        rec.addQuery('customer', true);

        rec.query();

        while (rec.next()) {

            if (currentUser.isMemberOf(rec.u_access_container_group.name.toString())) {
                result += rec.sys_id + ",";
            }
        }
        result = result.slice(0, -1);
        var qc = current.addQuery('company', "IN", result);
    }
})(current, previous);
1 ACCEPTED SOLUTION

M_iA
Kilo Sage

I figured this one out. As we had other BR's in play on the extended table, I added the following to the condition:

 

M_iA_0-1665737952391.png

This then worked as expected

View solution in original post

11 REPLIES 11

suvro
Mega Sage

Do something like this

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

    if (current.getTableName() == 'sn_customerservice_managed_service_case') {

        var result = [];
        var currentUser = gs.getUserID();

        var rec = new GlideRecord('customer_account');
        rec.addNotNullQuery('u_access_container_group');
        //rec.addQuery('u_managed_services',true);
        rec.addQuery('customer', true);

        rec.query();

        while (rec.next()) {

            if (currentUser.isMemberOf(rec.u_access_container_group.name.toString())) {
                result.push( rec.sys_id.toString());
            }
        }
     
       current.addQuery('company', "IN", result);
    }
})(current, previous);

anubhavritolia
Giga Sage

Hi @M_iA 

 

Have you tried log to see what value you are getting in 'result' variable and if that is expected?

 

Add a log in 3rd last line to see the value of result variable.

 

 

Hi @anubhavritolia 

I added: gs.info("Result is " + result);

But on going to syslog, I cannot see the result. This suggests that its seeing "if (current.getTableName() == 'sn_customerservice_managed_service_case') " as false?

Hi @M_iA 

 

Try to replace it to as below:

 

if(current.sys_class_name=='sn_customerservice_managed_service_case')

 

Also try to use logs to see if it is going inside If condition and while condition.