Pass a value depending on radio button selected to the subject line

New Here ,
Nov 07, 2020

Copy link to clipboard

Copied

I have 4 radio buttons with a button style as a check

Group name Shipping

radio button choices

Non-Emergency Parts Order1

Standard Overnight1

Priority Overnight1

2nd Day Air1

 

What I would like to do is this:

If the radio button selected is "Non-Emergency Parts Order1"

then a field value of "EmerText" will be null

if it is any of the other 3 then  "EmerText" will have a value of 'Rush"

 

I will then put the "Emertext" on the sujext line as follows

var subjectLine = EmerText + "D"+this.getField("District Office #").valueAsString + " " +this.getField("Customer name").valueAsString + " SR " + this.getField("Original SR #").valueAsString;

 

Following is the code I have. Issue is that it is not null when I chose "Non-Emergency Parts Order1"

Please help

var EmerText = this.getField("shipping");

if(event.target.value=="Non-Emergency Parts Order1") {
EmerText="";
} else {
EmerText="!!Rush ";
}

 

thanks

 

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

Thank for taking the time to explain your project.

 

Now that you broke it down like that it was a lot easier to figure this all out.

 

What I did in the form was to implement a Button with a JavaScript Mouse-up action event.

 

I also spotted some errors on you spelled one of the variables for the customer name field.

 

The variable had a sapce "customer name" and this is probably why the original script wasn't loading the emailing part, so I renamed it to "customerName".

 

This is the script that is working on my end,  and I am also attaching a copy of the PDF so you can test and see how all the field objects interact with each other:

 

 

// DECLARE THE VARIABLES

var EmerText = "Non-Emergency Parts Order";

var ship = this.getField("shipping");

var district = this.getField("district").valueAsString; 

var customerName = this.getField("customer name").valueAsString; 

var serialNum = this.getField("SR number").valueAsString; 

var toAddress = "email1@email.com; second email2@email.com";

var ccAddress = "317swwwervice@email.com; marlo.thom@email.com; scott.bdsdwe@dft.com";

var msgBody = this.getField("shipping").value + " Please Order";


// ESTABLISH AN IF / ELSE / IF CONDITION

    if (ship.value == EmerText) {

   this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]", cMsg:"D "+ msgBody})

   this.calculateNow();

} else {

   if (ship.value !== EmerText) {

  this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "!!Rush - D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]",  cMsg: "!!Rush - D "+msgBody})

  this.calculateNow();

  }
}

 

 

Here's a copy of the file:  Parts Order Template Test PDF 

 

NOTE: You may want to add an additional button to reset the form or just the radio buttons.

TOPICS
Acrobat SDK and JavaScript

Views

93

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

Pass a value depending on radio button selected to the subject line

New Here ,
Nov 07, 2020

Copy link to clipboard

Copied

I have 4 radio buttons with a button style as a check

Group name Shipping

radio button choices

Non-Emergency Parts Order1

Standard Overnight1

Priority Overnight1

2nd Day Air1

 

What I would like to do is this:

If the radio button selected is "Non-Emergency Parts Order1"

then a field value of "EmerText" will be null

if it is any of the other 3 then  "EmerText" will have a value of 'Rush"

 

I will then put the "Emertext" on the sujext line as follows

var subjectLine = EmerText + "D"+this.getField("District Office #").valueAsString + " " +this.getField("Customer name").valueAsString + " SR " + this.getField("Original SR #").valueAsString;

 

Following is the code I have. Issue is that it is not null when I chose "Non-Emergency Parts Order1"

Please help

var EmerText = this.getField("shipping");

if(event.target.value=="Non-Emergency Parts Order1") {
EmerText="";
} else {
EmerText="!!Rush ";
}

 

thanks

 

Adobe Community Professional
Correct answer by ls_rbls | Adobe Community Professional

Thank for taking the time to explain your project.

 

Now that you broke it down like that it was a lot easier to figure this all out.

 

What I did in the form was to implement a Button with a JavaScript Mouse-up action event.

 

I also spotted some errors on you spelled one of the variables for the customer name field.

 

The variable had a sapce "customer name" and this is probably why the original script wasn't loading the emailing part, so I renamed it to "customerName".

 

This is the script that is working on my end,  and I am also attaching a copy of the PDF so you can test and see how all the field objects interact with each other:

 

 

// DECLARE THE VARIABLES

var EmerText = "Non-Emergency Parts Order";

var ship = this.getField("shipping");

var district = this.getField("district").valueAsString; 

var customerName = this.getField("customer name").valueAsString; 

var serialNum = this.getField("SR number").valueAsString; 

var toAddress = "email1@email.com; second email2@email.com";

var ccAddress = "317swwwervice@email.com; marlo.thom@email.com; scott.bdsdwe@dft.com";

var msgBody = this.getField("shipping").value + " Please Order";


// ESTABLISH AN IF / ELSE / IF CONDITION

    if (ship.value == EmerText) {

   this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]", cMsg:"D "+ msgBody})

   this.calculateNow();

} else {

   if (ship.value !== EmerText) {

  this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "!!Rush - D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]",  cMsg: "!!Rush - D "+msgBody})

  this.calculateNow();

  }
}

 

 

Here's a copy of the file:  Parts Order Template Test PDF 

 

NOTE: You may want to add an additional button to reset the form or just the radio buttons.

TOPICS
Acrobat SDK and JavaScript

Views

94

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
Nov 07, 2020 0
Adobe Community Professional ,
Nov 07, 2020

Copy link to clipboard

Copied

Maybe like this?

 

var EmerText = this.getField("shipping");


if (event.value !=="") {

if (event.target.value === "Non-Emergency Parts Order1") { 

EmerText.value ="";

} else {

EmerText.value ="!!Rush ";

  }
}

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
Reply
Loading...
Nov 07, 2020 0
New Here ,
Nov 07, 2020

Copy link to clipboard

Copied

Thank you however this does not allow the email to open

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
Reply
Loading...
Nov 07, 2020 0
Adobe Community Professional ,
Nov 07, 2020

Copy link to clipboard

Copied

Sorry, unless I misunderstood everything in your inquiry, I was not aware that when you said 

 

"I will then put the "Emertext" on the sujext line as follows var subjectLine = EmerText + "D"+this.getField("District Office #").valueAsString + " " +this.getField("Customer name").valueAsString + " SR " + this.getField("Original SR #").valueAsString;"

 

that you were actually asking for a script to handle the automation of an email.

 

But in any case,  I did a mistake in the previous code.

 

The code below is a custom calculation script to be run from the textfield where you want to populate with the values of the radio buttons.

 

What I did , I created a group of mutually exclusive radio button (all with the  same name of "shipping" but different export values on each one.

 

 I assigned an export value of "Non-Emergency Parts Order1" (without the quotes) only on the first radio button. Every other radio buttons' export value are just "Choice2", "Choice3", "Choice4", etc.

 

var EmerText = this.getField("shipping");

if (EmerText.value !=="Off") {

if (EmerText.value == "Non-Emergency Parts Order1") { 

event.value ="";

} else {

event.value ="!!Rush ";

  }
}

 

The script I corrected is meant to answer this part of your inquiry:

 

"Following is the code I have. Issue is that it is not null when I chose "Non-Emergency Parts Order1"

Please help

var EmerText = this.getField("shipping");

if(event.target.value=="Non-Emergency Parts Order1") {
EmerText="";
} else {
EmerText="!!Rush ";
} "

 

 

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
Reply
Loading...
Nov 07, 2020 0
New Here ,
Nov 07, 2020

Copy link to clipboard

Copied

apologies, I still can not get to work.

this is all my code

 

//var EmerText="";

//var ship = this.getField("shipping");

//if(ship == "Non-Emergency Parts Order1") {

//EmerText = "2";
//} else {
//EmerText = "!!Rush - ";

// }


var toAddress = "email1@email.com;second email2@email.com";
var ccAddress = "317swwwervice@email.com;marlo.thom@email.com;scott.bdsdwe@dft.com";
var subjectLine = EmerText + "D"+this.getField("District Office #").valueAsString + " " +this.getField("Customer name").valueAsString + " SR " + this.getField("Original SR #").valueAsString;
var msgBody = ship + EmerText + "Please Order";

if (validateRequiredFields(this)) this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: subjectLine, cMsg: msgBody});

function validateRequiredFields(doc) {
var emptyFields = [];
for (var i=0; i<doc.numFields; i++) {
var f = doc.getField(doc.getNthFieldName(i));
if (f!=null && f.type!="button" && f.required && f.valueAsString==f.defaultValue) {
emptyFields.push(f.name);
}
}

if (emptyFields.length>0) {
app.alert("You must fill in the following fields:\n" + emptyFields.join("\n"));
return false;
}
return true;

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
Reply
Loading...
Nov 07, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

You've changed the first portion of the script again.

 

Is hard to tell what could be wrong as I can't see how you're employing the use of eradio buttons.

 

Maybe if you can share an example of this form it could be helpful. If you run this script from a radio button's action event it won't work like this.

 

That script that you have should be used in a textfield as custom calculation script, since your current script is trying to get the target event from the radio button group "shipping".

 

When the radio button that has this export value is checked the field with the custom script should populate the string value of "2" as declared in the EmerText variable. And when any other radio button in that group is checked, then  the custom script will populate a text string of "!!Rush - " according to the dclared variable.

 

However,  you keep declaring EmerText as a variable in your script without defining where are you getting the the value for EmerText from.

 

What is EmerText ?  Is it the name of another textfield?

 

You're doing this incorrectly.

 

So if we run your the first part of your current script  as custom calculation script from a textfield (not from a radio button), and if the variable "EmerText" is referring to another textfield, in which you want the event of this script to be populated to,  then it should be expressed like this:

 

var EmerText =  this.getField("EmerText");

var ship = this.getField("shipping");

if (ship.value === "Non-Emergency Parts Order1") {

EmerText.value = "2";

} else {

EmerText.value = "!!Rush - ";

 }

 

The slide below illustrate the result where the text field labeled as "Text19". It grabs the export value from the the already pre-defined group of radio buttons named as "shipping". Then it populates the resulting text string values to the "EmerText" field.

 

emertext1.png

 

Now, if the "EmerText" variable that you're declaring in in your current script was meant to be run from the "Text19" in my example above, then the script has to be modified slighlty since the event value will populate itself in the same field where the script is run from as a field target event.

 

It should be expressed like this:

 

var EmerText =  event.target;

var ship = this.getField("shipping");

if (ship.value === "Non-Emergency Parts Order1") {

EmerText.value = "2";

} else {

EmerText.value = "!!Rush - ";

 }

 

Aer you able to see the slight differences in how the same blueprint of your original script is  used in different fields? 

 

So, if you were running this script from the first radio button, for exaxmple , then it has to be modified.

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
Reply
Loading...
Nov 08, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

For the email part of your script I would strongly recommend to refer to Acrobat JavaScript Developer Guide:

 

Adobe Acrobat DC SDK Review, Markup, and Approval, Developing Acrobat® Applications Using JavaScript™ "Emailing PDF documents" , starting in page 115- 120

 

And also use the JavaScript for Acrobat API Reference, which explains in great detail with script examples how to use mailDoc() app method:

 

Adobe Acrobat SDK JavaScript API, JavaScript™ for Acrobat® API Reference,  "app methods", staring in page 96

 

 

 

 

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
Reply
Loading...
Nov 08, 2020 0
New Here ,
Nov 08, 2020

Copy link to clipboard

Copied

I appreicate the help. Below is a section of the form where I currently have check boxes.

I want to move to radio button so that only 1 can be selected. 

The javascript works with check boxes. 

I'm looking to see how I can capture the value of the selected radio button

radio group shipping

radio1 Choice Non-Emergency Parts Order
radio 2 Choice Standard Overnight
radio 3 Choice Priority Overnight
radio 4 Choice 2nd Day Air

 

Mario5FAA_0-1604870856699.png

Summary:

Change check box to radio button option so people can only select one. I still want the form to show a checkbox.
Radio button names
Non-Emergency Parts Order
Standard Overnight
Priority Overnight
2nd Day Air
For the subject in the email:
If the radio button selected is: [Non-Emergency Parts Order]
Subject will read “D [district #] [customer name] SR [number]”
If the radio button selected is any of the other three:
Standard Overnight
Priority Overnight
2nd Day Air
Subject will read “ !!Rush - D [district #] [customer name] SR [number]”

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
Reply
Loading...
Nov 08, 2020 0
Adobe Community Professional ,
Nov 08, 2020

Copy link to clipboard

Copied

Thank for taking the time to explain your project.

 

Now that you broke it down like that it was a lot easier to figure this all out.

 

What I did in the form was to implement a Button with a JavaScript Mouse-up action event.

 

I also spotted some errors on you spelled one of the variables for the customer name field.

 

The variable had a sapce "customer name" and this is probably why the original script wasn't loading the emailing part, so I renamed it to "customerName".

 

This is the script that is working on my end,  and I am also attaching a copy of the PDF so you can test and see how all the field objects interact with each other:

 

 

// DECLARE THE VARIABLES

var EmerText = "Non-Emergency Parts Order";

var ship = this.getField("shipping");

var district = this.getField("district").valueAsString; 

var customerName = this.getField("customer name").valueAsString; 

var serialNum = this.getField("SR number").valueAsString; 

var toAddress = "email1@email.com; second email2@email.com";

var ccAddress = "317swwwervice@email.com; marlo.thom@email.com; scott.bdsdwe@dft.com";

var msgBody = this.getField("shipping").value + " Please Order";


// ESTABLISH AN IF / ELSE / IF CONDITION

    if (ship.value == EmerText) {

   this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]", cMsg:"D "+ msgBody})

   this.calculateNow();

} else {

   if (ship.value !== EmerText) {

  this.mailDoc({cTo: toAddress, cCc: ccAddress, cSubject: "!!Rush - D "+"["+district+"] "+"["+ customerName+"] "+"["+serialNum+"]",  cMsg: "!!Rush - D "+msgBody})

  this.calculateNow();

  }
}

 

 

Here's a copy of the file:  Parts Order Template Test PDF 

 

NOTE: You may want to add an additional button to reset the form or just the radio buttons.

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
Reply
Loading...
Nov 08, 2020 0