Timing problem when retrieving Employee Form Results

Michael Nau
Mega Guru

We have a timing (?) problem when retrieving the results of an employee form from "asmt_metric_result".

 

The scenario:

  1. An HR Task of type "collect employee info" is created
  2. The employee form contains 3 questions with metric datatype "String" and 1 question with metric datatype "attachment" - all questions are mandatory
  3. An async Business Rule is triggered when the HR Task changes to "closed complete"
  4. 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:

  1. we are unable to retrieve all results because the records on "asmt_metric_result"  don't exist yet when the task is completed
  2. 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"
  3. there should be one result record for each question record, that is: 4 questions and 4 results
  4. 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?

1 ACCEPTED SOLUTION

Michael Nau
Mega Guru

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.

View solution in original post

11 REPLIES 11

Mohith Devatte
Tera Sage
Tera Sage

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

BR trigger:

 

MichaelNau_0-1692893366671.png

 

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

 

@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 

We've changed both the priority and the order to 10000, unfortunately this changes nothing - when the task closes, the results aren't there.