We are currently experiencing intermittent login issues on Community.  The team is actively working on a fix.

In Assessment instance(asmt_assessment_instance) form, there is a drop-down field 'status'.And a related list 'Metric Result' which stores questions and answer(Yes/No).Need to update status if all the questions are answered as 'No''

dipam3
Tera Contributor

In Assessment instance(asmt_assessment_instance) form, there is a drop-down field 'status'.And a related list 'Metric Result' which stores  questions and answer(as Yes/No).Need to update 'status' if all the questions are answered as 'No''. Tried below code in after insert, update BR but i am missing somewhere and it always go to 2nd log even if any ans is Yes

 

(function executeRule(current, previous /*null when async*/ ) {
var sysID = current.sys_id;
// Add your code here
var cinst = new GlideRecord('asmt_metric_result');
cinst.addQuery('instance', sysID);
cinst.addQuery('string_value', 'Yes');
cinst.query();
while (cinst.next()) {
gs.log('dip inside while next' +cinst.instance);
if (cinst.string_value == 'No') {
gs.log('Dip 2nd if ' + cinst.string_value);
current.u_status = 'Nothing Disclosed';
current.update();
}
}
})(current, previous);

 

3 REPLIES 3

Ashutosh Munot1
Kilo Patron
Kilo Patron

HI,

(function executeRule(current, previous /*null when async*/ ) {
var sysID = current.sys_id;
// Add your code here
var cinst = new GlideRecord('asmt_metric_result');
cinst.addQuery('instance', sysID);
cinst.addQuery('string_value', 'Yes');
cinst.query();
while (cinst.next()) {
gs.log('dip inside while next' +cinst.instance);
if (cinst.getValue('string_value') == 'No') {
gs.log('Dip 2nd if ' + cinst.string_value);
current.u_status = 'Nothing Disclosed';
current.update();
}
}
})(current, previous);

 

Thanks,
Ashutosh

Hi Ashutosh,

string_value is the field value . Thanks for your reply but i dont think the if condition is the issue.Please see below:

find_real_file.png

 

 

find_real_file.png

Community Alums
Not applicable

Hi,

I am understanding that if all answers are 'No', you want the Assessment 'Status' to be updated as 'Not Disclosed'

 

You can try an 'After' 'Update' BR on 'asmt_assessment_instance' table with Condition 'state changes to Complete'-

 

 

var totalMetric = 2; //Here update the number with the total number of questions in your survey
var count = 0;

var gr = new GlideAggregate('asmt_metric_result');
gr.addQuery('string_value', 'No');
gr.addQuery('instance', current.sys_id);
gr.addAggregate('COUNT');
gr.query();
if(gr.next()){
count = gr.getAggregate('COUNT');
}

if(count == totalMetric){
current.u_status = 'Nothing Disclosed';
current.update();
}