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

Hi,

The reason you are getting all results form the extended table also is that they have a valid entry in cmdb_ci_computer table as well. For eg, you can find the incident number on task table also(task table being the parent of incident table)

In this case you need to find any other attribute to differentiate the records of computer table vs extended tables.

 

You can try this:

 

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

if(check2.next())

{

if(check2.sys_class_name != 'cmdb_ci_computer')

{

//do something

}

else

{

//ignore

}

}

-Anurag

-Anurag

Actually it turns out the script did work properly as I posted it because I was already checking the class name.  However, there is a default business rule in SN that is supposed to check for conflicts in duplicate references that does not work properly.  It randomly returns values from the extended tables and produces erratic results and failures.  Once I disabled business rules from running on the transform table everything behaved as it should in the first place.

Cool.

-Anurag