• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

conditional line break

Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript , Windows

Views

146

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 20, 2019 Jul 20, 2019

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!="")

   

...

Likes

Translate

Translate
Community Expert ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

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.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

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 ?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

What do you intend for it to do, exactly?

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

body of email by this.mailDoc

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

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});

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

i will try

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

LATEST

you are awesome

it workssss

thank you so much

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

//

// Before sending the data, make sure that all required

// fields are valid

//

//  The "Ex2ValidFields" fucntion is located in the document script

//  If you copy this button action then you will also need to delete

//  this first if statement or copy the "Ex2ValidFields()"

//  fucntion and modify it to work with your form.

//

if(Ex2ValidFields())

{

   // This is the form return email, It’s hardcoded

   // so that the form is always returned to the same address

   // Change address on your form

   var cToAddr = this.getField("A/C TYPE").value;

   // First, get the client CC email address

   var cCCAddr ="";

    // Now get the beneficiary email only if it is filled out

   // Set the subject line for the email message

var cSubLine = this.getField("A/C REG").value+ " FLIGHT ENVELOPE";

   //  Set the body text for the email message

var f = this.getField("A/C TYPE");

var a = f.currentValueIndices;

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

                + "Date: " + this.getField("Date").value + "\n"

                + "Aircraft type: " + f.getItemAt(a, false) + "\n"

                + "Aircraft registration: "

                + this.getField("A/C REG").value + "\n"

                + "Route: " + this.getField("FROM1").value + "-"

                + this.getField("TO1").value + "-"

                + this.getField("TO2").value + "-"

                + this.getField("TO3").value + "-"

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

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

               "- Dispatch Release Sector 1\n" +

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

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

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

   // Send the entire PDF as a file attachment on an e-mail

   this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr,

                  cSubject: cSubLine, cMsg: cBody});

}

sometimes value of "Sector3" is empty, so how we delete or skip the empty line

and make it like

-sector2

-sector4

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 20, 2019 Jul 20, 2019

Copy link to clipboard

Copied

I answered that already.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines