- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 08:58 AM
We have a timing (?) problem when retrieving the results of an employee form from "asmt_metric_result".
The scenario:
- An HR Task of type "collect employee info" is created
- The employee form contains 3 questions with metric datatype "String" and 1 question with metric datatype "attachment" - all questions are mandatory
- An async Business Rule is triggered when the HR Task changes to "closed complete"
- The Business Rule retrieves the result records from "asmt_metric_result" and does its magic
This works on a PDI, but on our DEV instance we are encountering...
The problem:
- we are unable to retrieve all results because the records on "asmt_metric_result" don't exist yet when the task is completed
- to verify, we are calling two GlideAggregates when our BR fires - one counts records on "asmt_assessment_instance_question", the other on "asmt_metric_result"
- there should be one result record for each question record, that is: 4 questions and 4 results
- however, we're seeing 4 questions records and 1 result record - this is always the "attachment" question
What is causing this delay in the creation of the records on "asmt_metric_result"?
How can we know when to collect the results, if not by looking at the state of the parent task?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 09:17 AM
Hi, a quick follow up: We opened a case with ServiceNow regarding this behavior, and the outcome was: That's just how it is designed. In other words, if you want to know when all results for an assessment have been written, you're out of luck. There's no state change you can watch, and no events are emitted.
Our solution to this was to move the actions we want to perform on the results to a Flow - which creates so much overhead that by the time our Flow action triggers, all results have been written. This might fail if you have an assessment with a large number of questions, but it's the best option you have.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:01 AM
Hello @Michael Nau ,
Can you post your BR script here please ?
Also try changing the order of the BR to more value
HOpe this helps
Mark the answer correct if this helps you
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:15 AM - edited 08-24-2023 09:16 AM
BR trigger:
BR script with GlideAggregates:
(function executeRule(current, previous /*null when async*/) {
var grParentCase = current.parent.getRefRecord();
retrieveMetricResults(current, grParentCase);
})(current, previous);
function retrieveMetricResults(current, parent) {
gs.info("dev: retrieveMetricResults");
// debug start
var grQuestionCount = new GlideAggregate("asmt_assessment_instance_question");
grQuestionCount.addEncodedQuery("instance=" + current.survey_instance);
grQuestionCount.addAggregate("COUNT");
grQuestionCount.query();
grQuestionCount.next();
gs.info("dev: question count: " + grQuestionCount.getAggregate("COUNT"));
var grResultCount = new GlideAggregate("asmt_metric_result");
grResultCount.addEncodedQuery("instance=" + current.survey_instance);
grResultCount.addAggregate("COUNT");
grResultCount.query();
grResultCount.next();
gs.info("dev: result count: " + grResultCount.getAggregate("COUNT"));
// debug end
}
Result:
dev: retrieveMetricResults
dev: question count: 4
dev: result count: 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:22 AM
@Michael Nau you were talking about an async BR right which will retrieve records can you ping that script and also please change the order of the BR to higher number like 10000 and try
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-24-2023 09:30 AM
We've changed both the priority and the order to 10000, unfortunately this changes nothing - when the task closes, the results aren't there.