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

Tai Vu
Kilo Patron
Kilo Patron

Hi @matthew_hughes 

Give this a try. And also, keep the string query in a double quote marks.

var query = "sys_created_onDATEPARTMidnight hour@javascript:gs.datePart('hour','0','GE')^sys_created_onDATEPART8 am hour@javascript:gs.datePart('hour','8','LT')";
current.addEncodedQuery(query);

 

Let me know if it works for you.

 

Cheers,

Tai Vu

Hi @Tai Vu  I've tried the following amendments, but the field is not updating:

matthew_hughes_0-1696842443621.png

 

(function executeRule(current, previous /*null when async*/) {
var shift1Query = "sys_created_onDATEPARTMidnight hour@javascript:gs.datePart('hour','0','GE')^sys_created_onDATEPART8 am hour@javascript:gs.datePart('hour','8','LT')";
var shift2Query = "sys_created_onDATEPART8 am hour@javascript:gs.datePart('hour','8','GE')^sys_created_onDATEPART4 pm hour@javascript:gs.datePart('hour','16','LT')";
var shift3Query = "sys_created_onDATEPART4 pm hour@javascript:gs.datePart('hour','16','GE')";
 
if (current.addEncodedQuery(shift1Query)) {
current.u_shift_opened_in = 'shift_1';
}
if (current.addEncodedQuery(shift2Query)) {
current.u_shift_opened_in = 'shift_2';
}
if (current.addEncodedQuery(shif3Query)) {
current.u_shift_opened_in = 'shift_3';
}
// Add your code here
 
})(current, previous);
 
I was just wondering what else I need to change.

Hi @matthew_hughes 

I'm not sure what do you intend to do. Can you be more specific on the requirements so maybe I can help to adjust your script.

Hi @Tai Vu 

I'm wanting to set the value of the 'u_shift_opened_in' field depending on when the request is created. The logic should be:
If the request is created at or after midnight and before 8am, then the value of the 'u_shift_opened_in' field 

should be 'Shift 1'

 

If the request is created at or after 8am and before 4pm, then the value of the 'u_shift_opened_in' field should be 'Shift 2'

 

If the request is created at or after 4pm, then the value of the 'u_shift_opened_in' field should be 'Shift 3'