Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Query and log the number of incidents created in the past 3 days where the caller is ‘Joe Employee'

Philip Conforzi
Tera Contributor

Hello ServiceNow community,

 

I hope you're doing well. 

 

I've been practicing in my own developer instance and have been working on a solution for the prompt: "Query for all incidents created in the past 3 days where the caller is ‘Joe Employee’…log a count of records returned".

 

I provided a solution which I thought would work, but it provided my with a count of 0 records, which upon review should have provided me with a count of 10 that fit the parameters. 

 

Please see an image of the business rule I scripted below. Let me know your thoughts and if I've made any errors. Thanks!

 

PhilipConforzi_0-1706049711226.png

 

 

1 ACCEPTED SOLUTION

Tai Vu
Kilo Patron
Kilo Patron

Hi @Philip Conforzi 

It's because of the line 7 from your script. Let's try to make this change.

From

gaIncident.addQuery('caller_id', 'Joe Employee');

To one of those

gaIncident.addQuery('caller_id', '<the_Joe_Employee_sys_id');

 

gaIncident.addQuery('caller_id.name', 'Joe Employee');

 

Cheers,

Tai Vu

 

View solution in original post

2 REPLIES 2

ahefaz1
Mega Sage

Hi @Philip Conforzi ,

 

You can always use the list view to construct filters. These filters you can use in GlideRecord.

I was able to create a filter on my PDI.

 

ahefaz1_0-1706057487769.png

 

ahefaz1_3-1706057900764.png

 

 

ahefaz1_2-1706057692138.png

 

 

You can right click and copy the query, and use the gr.addEncodedQuery API.

"sys_created_onRELATIVEGT@dayofweek@ago@3"

 

 

var ga = new GlideAggregate('sn_hr_core_case');
ga.addEncodedQuery('sys_created_onRELATIVEGT@dayofweek@ago@3');
ga.addAggregate('COUNT');
ga.query();

if (ga.next()) {
  var count = ga.getAggregate('COUNT');
  gs.info('Number of HR Cases : ' + count);
}

 

 

Please change this to match your needs.

 

Please accept solution OR mark helpful.

 

Thanks,

Tai Vu
Kilo Patron
Kilo Patron

Hi @Philip Conforzi 

It's because of the line 7 from your script. Let's try to make this change.

From

gaIncident.addQuery('caller_id', 'Joe Employee');

To one of those

gaIncident.addQuery('caller_id', '<the_Joe_Employee_sys_id');

 

gaIncident.addQuery('caller_id.name', 'Joe Employee');

 

Cheers,

Tai Vu