Adding a Trend encoded query to a Business Rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 01:27 AM
In a Business Rule, I'm wanting to add the following Trend search:
When I right click on the query and select 'Copy Query', it appears as:
sys_created_onDATEPARTMidnight hour@javascript:gs.datePart('hour','0','GE')^sys_created_onDATEPART8 am hour@javascript:gs.datePart('hour','8','LT')
I'm wanting to copy this query and apply it in a Business Rule as a condition. However, I get the following error:
If somebody could please explain what I need to do, that would be great.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 12:28 AM - edited 10-10-2023 12:30 AM
Hi @Tai Vu
Another query, I'm wanting to set the value of the 'u_shift_closed_in' field depending on when the request is created. The logic should be:
If the request is closed at or after midnight and before 8am, then the value of the 'u_shift_closed_in' field
should be 'Shift 1'
If the request is closed at or after 8am and before 4pm, then the value of the 'u_shift_closed_in' field should be 'Shift 2'
If the request is created at or after 4pm, then the value of the 'u_shift_closed_in' field should be 'Shift 3'
What would the code need to be?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 12:31 AM - edited 10-10-2023 12:32 AM
Yup it looks good. Just rename the variable "timeCreated" to "timeClosed" for less confusion.
Don't forget to configure the corresponding conditions to trigger the rule when the ticket get closed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 12:36 AM
Hi @Tai Vu
I applied this script:
(function executeRule(current, previous /*null when async*/ ) {
var timeCreated = current.getDisplayValue('closed_at').split(' ')[1];
var shift = (timeCreated >= "00:00:00" && timeCreated <= "08:00:00") ? 'shift_1' : (timeCreated <= "16:00:00") ? 'shift_2' : 'shift_3';
current.setValue('u_shift_closed_in', shift);
})(current, previous);
Would this work?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 01:21 AM
Yes the script should work for the Closed cases. => Resolved Incident will be Closed after 7 days (based on the property).
Also make sure to combine with below conditions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-10-2023 01:49 AM