- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 10:26 AM
I have a before-query business rule that runs on the IT Service table. However, since Service Component is a child table of the IT Service table it is running on Service Component as well and subsequently blocks all the data since the query in the BR is only set up to align with IT Services.
Since I don't have access to 'current' in a before-query business rule, I cannot specify in the condition that the BR should only run if the current table is the IT Service table since you can only really mention user or session specific details in the condition field.
How can I stop the before-query business rule running on the child table?
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 05:29 PM
Hi Olivia,
You have access to current.getTableName() inside a query business rule.
So you can add a condition on your query business rule to only run on that parent table using current.getTableName() == 'name_of_table'
Also if you want to see all of your records of Service Component when in IT Service table you should simply add a OR condition to include other tables by making a condition including every records where sys_class_name is not IT Service. In encoded query or with an addOrContion('sys_class_name', '!=', 'name_of_table')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-04-2016 05:29 PM
Hi Olivia,
You have access to current.getTableName() inside a query business rule.
So you can add a condition on your query business rule to only run on that parent table using current.getTableName() == 'name_of_table'
Also if you want to see all of your records of Service Component when in IT Service table you should simply add a OR condition to include other tables by making a condition including every records where sys_class_name is not IT Service. In encoded query or with an addOrContion('sys_class_name', '!=', 'name_of_table')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2016 01:10 AM
Hi Laurent,
Thank you for this response I've tried it and it works perfectly.
How is that we can use current.getTableName() but can't use current to find other record-specific details?
Regards,
Olivia
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-02-2017 07:10 AM
I know it's an old thread, but I stumbled across it so thought I'd explain why you have access to getTableName() but not record specific data.
When running a normal GlideRecord, it takes the pattern of:
var gr = new GlideRecord('incident');
gr.query();
A before query business rule, is no different, but instead of gr, we use current:
var current = new GlideRecord('incident');
current.query();
Then as the name suggests, before query business rules get inserted before the current.query() function is called:
var current = new GlideRecord('incident');
//Before query business rule goes here
current.addQuery('active', true);
current.query();
So as you can see, when the GlideRecord is first set up, we pass in the table name. This is where the getTableName() attribute comes from. It's the initial table that the GlideRecord was set up against. We didn't need to do the current.query() to know that the table that we're querying against is the incident table. But because we haven't done the query, we have no specific details about the actual records themselves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2016 05:34 AM
Hi Olivia,
You can't use record-specific details as in a query business rule you did not retrieve any records. However, current.getTableName() seems to access an attribute that is defined in the query itself and is not record specific.
But as my second proposition suggest, you can build logic around record specific element using the right query, for that purpose, it is easier to go in liast, build the filter and copy the query. You can then add it using current.addEncodedQuery('query');
For exemple let's say you add a query so users can only see tasks assigned to them, but you would want the "abc" category to be seen by every one. In this case you current.getTableName() does not give the required information.
So you could do: current.addEncodedQuery('assigned_to=javascript:gs.getUserID()^NQcategory=abc');