- 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
‎02-07-2019 09:19 AM
That appears to have worked! Thanks very much!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2019 01:56 AM
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')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2019 02:09 AM
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')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-08-2019 02:34 AM
Thank you 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-23-2020 07:52 PM
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!