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''
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 12:37 AM
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 12:49 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 01:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-08-2020 03:44 AM
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();
}
