Trying to stop a Business Rule running on an extended table

Wayne Richmond
Tera Guru

Hey. I have a before Query Business Rule that runs on all tables extending from Task [task]. It provides Company separation for us. However, I don't want it to apply to a custom table called Order [u_order] that extends from task. Here is the rule:

find_real_file.png

find_real_file.png

The code:

function onBefore(current, previous) {
        var userCurrentCompany = gs.getUser().getCompanyID(),
	
		dotWalkPath = 'u_customer.company',
		dotWalkPathOr = '^ORu_customer.company=NULL';

        if (userCurrentCompany != '') {
            current.addEncodedQuery(dotWalkPath + "=" + userCurrentCompany + dotWalkPathOr);
        } else current.addDomainQuery("global");
}

I've tried to add a condition using the condition builder: Task type is not Order. This doesn't work. I also tried adding the following query to the end of the Condition: && sys_class_name!=u_order but this also didn't work. Any ideas?

1 ACCEPTED SOLUTION

Try this

 

gs.getSession().isInteractive() && !gs.hasRole("admin") && current.getTableName() !='u_order'

 

-Anurag

View solution in original post

12 REPLIES 12

That appears to have worked! Thanks very much!!

Hey buddy. Thanks again for your assistance. Quick follow-up question if I may. How would I add another table to that condition? Would it be something like this?

gs.getSession().isInteractive() && !gs.hasRole("admin") && (current.sys_class_name!='u_order' || current.sys_class_name!='u_suspicion')

 

 

You can add another table with && itself, not ||, like below

gs.getSession().isInteractive() && !gs.hasRole("admin") && (current.sys_class_name!='u_order' && current.sys_class_name!='u_suspicion')

-Anurag

Thank you 🙂

Hi Anurag,

This reply seems the closest thing I have found to an issue I have trying to constrain a query to a "parent" table and not any tables that extend it, specifically Computers.  Here is my code:

var check2 = new GlideRecord('cmdb_ci_computer');
check2.addQuery('name',source.u_computername);
check2.addQuery('sys_class_name', 'cmdb_ci_computer');
check2.query();

But this does not work, the sys_class_name line is seemingly ignored and the query returns results from the extended table.  Any advice how to make this work?

Thanks!