Skip to main content
Known Participant
July 20, 2019
Answered

conditional line break

  • July 20, 2019
  • 9 replies
  • 1235 views

hello

i have 3 lines

                this.getField("Sector2").value +"\n" +

                this.getField("Sector3").value + "\n" +

                this.getField("Sector4").value + "\n";

but sometime "Sector3" value equal empty so the line break still show like:

-sector2

-Sector4

i want remove the line break when "Sector3" value equal empty to be like:

-sector2

-sector4

thank you in advance

This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer try67

body of email by this.mailDoc


Then you need to append the values directly to the cBody string, like this:

var cBody = "Thank you for submitting your report.\n\n" +

"CONTENT:\n\n" +

"- Dispatch Release Sector 1\n";

if (this.getField("Sector2").valueAsString!="")

    cBody+="- Dispatch Release Sector 2: "+this.getField("Sector2").valueAsString+"\n";

if (this.getField("Sector3").valueAsString!="")

    cBody+="- Dispatch Release Sector 3: "+this.getField("Sector3").valueAsString+"\n";

if (this.getField("Sector4").valueAsString!="")

    cBody+="- Dispatch Release Sector 4: "+this.getField("Sector4").valueAsString+"\n";

this.mailDoc({cMsg: cBody});

9 replies

try67
Community Expert
Community Expert
July 20, 2019

You can do it like this:

var s = "";

if (this.getField("Sector2").valueAsString!="") s+=this.getField("Sector2").valueAsString+"\n";

if (this.getField("Sector3").valueAsString!="") s+=this.getField("Sector3").valueAsString+"\n";

if (this.getField("Sector4").valueAsString!="") s+=this.getField("Sector4").valueAsString+"\n";

The variable s will hold your full text at the end.

Known Participant
July 20, 2019

var D2 = "- Dispatch Release Sector 2";

var D3 = "- Dispatch Release Sector 3";

var D4 = "- Dispatch Release Sector 4";

var cBody = "Thank you for submitting your report.\n\n"

               "CONTENT:"+ "\n\n" +

               "- Dispatch Release Sector 1\n";

if (this.getField("Sector2").valueAsString!="") D2+=this.getField("Sector2").valueAsString+"\n";

if (this.getField("Sector3").valueAsString!="") D3+=this.getField("Sector3").valueAsString+"\n";

if (this.getField("Sector4").valueAsString!="") D4+=this.getField("Sector4").valueAsString+"\n";

i complete this script but it does not work, it that right ?

try67
Community Expert
Community Expert
July 20, 2019

What do you intend for it to do, exactly?