
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-10-2023 07:53 AM
Good afternoon,
When an assessment is still in a ready to take state, we would like to send out a reminder to the user if the due date is within 4 days of the current date. Before I even get into script include and the like to work out how to pass the user and assessment number into an email, I thought I would just try and query the table to ensure we can at least identify the affected assessments. I am running the following background script, but so far I havent managed to return anything, despite having at least 6 records that currently meet the search criteria. Interestingly, the value for metric_type appears to be a sys_id, but it doesnt work with that either. Can anyone advise where we are going wrong please.
var now = new GlideDateTime();
now.addDaysUTC(4);
var gr = new GlideRecord('asmt_assessment_instance');
gr.addQuery('state','ready');
gr.addQuery('metric_type','demand');
gr.query();
while (gr.Next()) {
var due = new GlideDateTime(gr.due_date);
if (due.after(now)) {
gs.info('Assessment ' + asmt_assessment_instance.number + ' has not been completed');
}
}
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2023 05:37 AM
You can use the same method and build the metric_type condition into the filter you build in the list:
Then copy the query that is generated. This is what I get for the encoded query on my instance:
state=ready^due_dateRELATIVELT@dayofweek@ahead@4^metric_type=0556fa9a8f12110040f82ab2f0f923f8

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2023 06:34 AM
var gr = new GlideRecord('asmt_assessment_instance');
gr.addEncodedQuery("metric_type.evaluation_method=assessment^state=ready^metric_type=0556fa9a8f12110040f82ab2f0f923f8^due_dateRELATIVELT@dayofweek@ahead@10");
gr.query();
gs.print(gr.getRowCount()); // Prints the number of records found by the query above
while (gr.next()) { // Loop through records in the query
gs.print(gr.getDisplayValue()); // Print the display value of each record
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-11-2023 08:11 AM