How to acces Task number from Assessment instance table

KS7
Kilo Contributor

Hi All,

I am trying to fetch the value of task number(task_id) i.e. change number from Assessment Instance (asmt_assessment_instance) table as soon as a record is inserted using a BR

Please refer below screenshot for BR and table

BR is created After Insert 

But every time record is getting inserted in assessment instance table, no task_id is getting returned in BR

Please suggest, how should I fetch task_id of the inserted record

 

find_real_file.png

 

 

 

 

 

find_real_file.png

 

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

From your BR name I am assuming that you want to count the number of assessments taken for a particular Change request.

 

Try the below BR-

On Assessment Instance table, every time an instance for "Change Risk Assessment" is set to Complete state-

find_real_file.png

 

Script will be-

 

var otherAssessmentCount = 0;
var checkIfOtherAssessment = new GlideAggregate(current.getTableName());
checkIfOtherAssessment.addEncodedQuery('metric_type='+current.metric_type.sys_id+'^task_id='+current.task_id.sys_id);
checkIfOtherAssessment.addAggregate('COUNT');
checkIfOtherAssessment.query();
if(checkIfOtherAssessment.next()){
otherAssessmentCount = checkIfOtherAssessment.getAggregate('COUNT');
}
var chg = new GlideRecord('change_request');
chg.get(current.task_id);
chg.u_total_assessments_taken = otherAssessmentCount; //Here add the name of your custom field on change_request
chg.update();

 

 

And the change request will be updated-

 

find_real_file.png

 

find_real_file.png

 

View solution in original post

19 REPLIES 19

Community Alums
Not applicable

Can you try with async in your BR once?

 

find_real_file.png

Hi Shruthiub,

 async is working but I needed that information as soon as the record is getting inserted.

Community Alums
Not applicable

Hi, There is a delay between when the assessment record is inserted and the change number gets populated. You can go ahead with 'async' BR. It works the same way as an 'After' BR except asynchronously. 

Since it is an 'Insert' 'Async' BR on assessment table, you can still use this BR to get/update change record after an assessment instance is created for the same.

 

Community Alums
Not applicable

From your BR name I am assuming that you want to count the number of assessments taken for a particular Change request.

 

Try the below BR-

On Assessment Instance table, every time an instance for "Change Risk Assessment" is set to Complete state-

find_real_file.png

 

Script will be-

 

var otherAssessmentCount = 0;
var checkIfOtherAssessment = new GlideAggregate(current.getTableName());
checkIfOtherAssessment.addEncodedQuery('metric_type='+current.metric_type.sys_id+'^task_id='+current.task_id.sys_id);
checkIfOtherAssessment.addAggregate('COUNT');
checkIfOtherAssessment.query();
if(checkIfOtherAssessment.next()){
otherAssessmentCount = checkIfOtherAssessment.getAggregate('COUNT');
}
var chg = new GlideRecord('change_request');
chg.get(current.task_id);
chg.u_total_assessments_taken = otherAssessmentCount; //Here add the name of your custom field on change_request
chg.update();

 

 

And the change request will be updated-

 

find_real_file.png

 

find_real_file.png

 

Thank you Shruthi, it's working 🙂