- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2019 06:00 AM
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:
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?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-07-2019 09:08 AM
Try this
gs.getSession().isInteractive() && !gs.hasRole("admin") && current.getTableName() !='u_order'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2020 01:17 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2020 07:05 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2020 07:24 AM
Cool.