How to check if field has a value in a script

postwick
Giga Expert

I am working within an email script.   I tried:

if (gr.work_start.getDisplayValue != null) { template.print(....);}

and

if (gr.work_start.getDisplayValue != "") { template.print(....);}

Both result in the code being executed even if there is no value.

2 REPLIES 2

mamann
Mega Guru

Since you're just checking if a field value is empty, you don't need to use getDisplayValue(). You can do something like.



if (!gr.work_start) {


//do something


}



The reason your piece doesn't work, even with getDisplayValue is because getDisplayValue is a method and needs to end with ().


So, your line of code would be



if (gr.work_start.getDisplayValue() != null) {


//do something


}


if (gr.work_start) { template.print(....); }



Worked perfectly, thanks!