Adding a Trend encoded query to a Business Rule

matthew_hughes
Kilo Sage

In a Business Rule, I'm wanting to add the following Trend search:

matthew_hughes_0-1696839938557.png

 

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:

matthew_hughes_1-1696840022620.png

 

If somebody could please explain what I need to do, that would be great.

16 REPLIES 16

Hi @matthew_hughes 

Let's try the below approach.

  1. Create your Before Insert Business Rule
  2. 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

When I do that now, it literally displays the field as 'shift_2':

 

matthew_hughes_1-1696851521892.png

 

when it should be 'Shift 2' from the options:

 

matthew_hughes_0-1696851418618.png

 

Hi @matthew_hughes 

It's because of this field.

TaiVu_0-1696857695365.png

 

Changes from "-- None --" to "Dropdown with -- None --".

 

Thanks. That worked

Hi @matthew_hughes 

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