Before query business rule on task_sla table not working

Aruna Sree Yela
Tera Guru

Hi,

 

I want to hide incident task slas with SLA definition "N Incident Resolution SLA", I tried to restrict them using before query BR. The if blocks are triggering fine with the info messages, but the query is not applying. Can anyone please help me.

 

Here is the details of BR

 

Table : task_sla

 

ArunaSreeYela_0-1688883803565.png

 

Note: "u_type_of_user" is a field in sys_user table

 

Thanks 🙂

 

 

1 ACCEPTED SOLUTION

Arun_S1
Tera Guru
Tera Guru

@Aruna Sree Yela I am assuming that you do not want to display some SLA records for a certain type of user.

 

1. I created a field in my "sys_user" table called 'u_type_of_user' and provided the choices 'external' & 'internal'. If the logged in user is external, I don't want few SLA records to be displayed. (please correct me if my understanding is wrong).

 

2. Added a new before query Business Rule on the 'task_sla' table with the below script.

 

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

	// Add your code here
	var user_rec=new GlideRecord('sys_user');
	user_rec.get(gs.getUserID());
	if(user_rec.u_type_of_user=='external'){
		current.addEncodedQuery('sla!=35420982d732220035ae23c7ce610393');
	}

})(current, previous);

 

This script will not allow me to see the Task SLA records that belongs to a specific SLA definition if I am an external, else it will be as usual.

 

If your expectation is to modify the query that is executed against the TASK SLA table, then you should use the variable current. In your above script 17-31 needs to be rewritten to use current.addQuery instead of gr.query.

 

Please mark the appropriate response as correct answer and helpful.

 

Thanks!!

View solution in original post

7 REPLIES 7

The BR on the sla_task table should do the work. please check.

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

    // Add your code here
    var user_rec = new GlideRecord('sys_user');
    user_rec.get(gs.getUserID());
    if (user_rec.u_type_of_user == 'external') {
        var Ngroups = new GlideRecord('sys_user_grmember');
        Ngroups.addEncodedQuery('group.nameSTARTSWITHinternal^group.active=true^user=' + gs.getUserID());
        Ngroups.query();
        if (!Ngroups.next()) {
            current.addEncodedQuery('sla!=35420982d732220035ae23c7ce610393');
        }
    }

})(current, previous);

 

Please mark the appropriate response as correct answer and helpful.

Thanks!!

@Aruna Sree Yela did you get a chance to check this Business Rule, is it working as expected.

 

Please mark the appropriate response as correct answer and helpful.

Thanks!!

Kindly accept the solution if this answered your query.

 

Thanks!!