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 @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?

Hi @matthew_hughes 

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.

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?

Hi @matthew_hughes 

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.

TaiVu_0-1696925953302.png

 

Hi @Tai Vu 

 

I've applied the following to my Business Rule:

matthew_hughes_0-1696927732728.png

 

matthew_hughes_1-1696927766578.png