OL Learn

Conditionally display fields Detail Table


#1

I want to only display values for fields that aren’t equal to 0.00 in a detail table. If I use the below code it works only if all rows in the table are equal to 0.00

if (record.tables[“detail2”][0].fields[“Postponed”] == “0.00”){
results.hide();
}

If one row has a value of, say 20.00, then all rows show, even if they are 0.00. How can I fix this?


#2

Hi marrd,

This is most likely caused by the fact that your selector is not specific. E.g. it hits all rows. The following shows an expanded Text Script for a detail table value. I embedded the check in the each loop and set the result variable to an empty string.

Hope this helps,

Erik

results.each(function(index) {
	var field, result = "";
	
	field = record.tables["detail2"][index].fields["PostPoned"];
	if (field !== "") result += field;
	
	if( field == "0.00") {
		result = "";
	}
	
	this.html(result);
		
});

#3

Thank you Erik, this works until I use formatter.currency(result), then it displays the 0.00 values again

results.each(function(index) {
var field, result = “”;

field = record.tables["detail2"][index].fields["PostPoned"];
if (field !== "") result += field;

if( field == "0.00") {
	result = "";
}

this.html(formatter.currency(result));

});


#4

Hi marrd,

Your script should be returning an error because the way it is written one cannot format what is essentially an empty string. I assume your field in the mapper is set to currency too and treat empty as 0 is NOT checked. Simply modify your script to apply the formatting prior to checking if it is 0.00.

This is my test code:

results.each(function(index) {
	var field, result = "";
	
	field = record.tables["detail"][index].fields["Field1"];
	if (field !== "") result += formatter.currency(field);
	
	if( field == "0.00") {
		result = "";
	}
	
	this.html(result);
});

Regards,
S


#5

Perfect, thanks so much