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-09-2023 04:13 AM
Let's try the below approach.
- Create your Before Insert Business Rule
- Add below script to your Advanced tab
(function executeRule(current, previous /*null when async*/ ) {
var timeCreated = current.getDisplayValue('sys_created_on').split(' ')[1];
var shift = (timeCreated <= "08:00:00") ? "shift_1" : (timeCreated <= "16:00:00") ? "shift_2" : "shift_3";
current.setValue('u_shift_opened_in', shift);
})(current, previous);
Let me know if it works for you...
Cheers,
Tai Vu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 04:39 AM
When I do that now, it literally displays the field as 'shift_2':
when it should be 'Shift 2' from the options:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 06:22 AM
It's because of this field.
Changes from "-- None --" to "Dropdown with -- None --".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 07:41 AM
Thanks. That worked
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-09-2023 08:01 AM
Great! Is it worth a thumbs up? 😁
Please mark my comments as solution and helpful so it might help other people in the same scenario.
Cheers,
Tai Vu