How to hide the labels from summary field if no value is updated from variable?

Vijaya13
Tera Contributor

I have created a summary field from RITM table and it displays all the variables details there.. But, I could see that empty variables labels are displaying which I want to hidden from the summary. How can I do this?

I'm using below Business Rule to update the Summary details:

(function executeRule(current, previous /*null when async*/) {

// This concatenates all variables into a u_summary field in RITM table

var details = '';
var set = new GlideappVariablePoolQuestionSet();
set.setRequestID(current.sys_id);
set.load();
var vs = set.getFlatQuestions();
for (var i=0; i < vs.size(); i++) {
if(vs.get(i).getLabel() != '') {
details += vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n";
}
}

current.u_summary = details;

})(current, previous);

1 ACCEPTED SOLUTION

Shruti
Mega Sage
Mega Sage

Hi,

Add below highlighted part in IF condition

if(vs.get(i).getLabel() != '' && JSUtil.notNil(vs.get(i).getDisplayValue()) ){
details += vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n";
}

View solution in original post

3 REPLIES 3

Shruti
Mega Sage
Mega Sage

Hi,

Add below highlighted part in IF condition

if(vs.get(i).getLabel() != '' && JSUtil.notNil(vs.get(i).getDisplayValue()) ){
details += vs.get(i).getLabel() + " = " + vs.get(i).getDisplayValue() + "\n";
}

Thank you @stark

@Shruti  - Hi, this was really helpful thank you - we added JSUtil.notNil(vs.get(i).getDisplayValue()) ){ to the if condition of our mail script and it removed the empty variables from our variable summary mail script on a notification, which is exactly what we wanted! thank you!

 

We have one question - We have checkbox variables on some of our record producers, and if these are not selected, their value equals false. Which means they show up on our variable summary on our notification because the value is completed.

What can we add to this same IF condition, to ensure the checkbox variables that are set as false are also not shown on the variable summary as part of our 
notification? We have tried vs.get(i).getDisplayValue() == 'false' however that didnt work