Adding an additional email based on radio button selection
Copy link to clipboard
Copied
Hello all,
I have code setup, which checks all required fields and uses a pop up box to re-iterate what has been missed and is required. Once the form is checked the email is generated, which all works fine.
However, I have now been asked to add 2 additional email address to the CC line dependant on the selection of 2 radio button groups further down the form. Add email address 1 if radio group (Contract Hire) is selected "Yes" and/or Add email address 2 if radio group (Service Contract) is selected"Yes"
I have tried with my limited knowledge of code and have checked the forums for any similar questions.requests.
Is this possible to make this happen?
My code on the submit button is currently this:
if (this.getField("salesman").valueAsString==this.getField("salesman").defaultValue) {
app.alert("You must select a Sales Person.");
} else if (this.getField("dealdate").value=="") {
app.alert("You must select todays date.");
} else if (this.getField("customerdetails").valueAsString==this.getField("customerdetails").defaultValue) {
app.alert("You must select a customer type.");
} else if (this.getField("customeraccount").display==display.visible && this.getField("customeraccount").valueAsString==""){
app.alert("Please enter a Customer Account number.");
} else if (this.getField("tradingname").valueAsString==""){
app.alert("Please enter the customers full trading name.");
} else if (this.getField("customeraddress").valueAsString==""){
app.alert("Please enter the customers full address.");
} else if (this.getField("customerphone").display==display.visible && this.getField("customerphone").valueAsString==""){
app.alert("Please enter a Customer contact number.");
} else if (this.getField("financeyn").valueAsString==this.getField("financeyn").defaultValue) {
app.alert("You must select if Finance is required.");
} else if (this.getField("financecompany").display==display.visible && this.getField("financecompany").valueAsString==this.getField("financecompany").defaultValue){
app.alert("Please select a Finance Company from the drop down list.");
} else if (this.getField("monthrv").display==display.visible && this.getField("monthrv").valueAsString==""){
app.alert("Please enter a term length in months.");
} else if (this.getField("turfin").display==display.visible && this.getField("turfin").valueAsString==this.getField("turfin").defaultValue){
app.alert("Please select who is purchasing the unit back at the end of the hire contract.");
} else if ((this.getField("date&send").valueAsString==this.getField("date&send").defaultValue)) {
app.alert("You must select 'Yes' or 'No' on the immediate invoice dropdown.\n\nPlease check with Dan or Jeremy if selecting 'Yes' on a unit which is not in stock..");
} else if (this.getField("order-stock1").valueAsString==this.getField("order-stock1").defaultValue) {
app.alert("You must select if the unit is in stock or requires ordering.");
} else if (this.getField("order-stock1").value=="stock" && this.getField("stocknumber1").display==display.visible && this.getField("stocknumber1").valueAsString==""){
app.alert("You must enter at least one stock number.");
} else if (this.getField("order-stock1").value=="order" && this.getField("orderfrom1").display==display.visible && this.getField("stocknumber1").valueAsString==""){
app.alert("You must enter at least one supplier name.");
} else if (this.getField("order-stock1").value=="stock&order" && this.getField("stocknumber1a","orderfrom1a").display==display.visible && this.getField("stocknumber1a","orderfrom1a").valueAsString==""){
app.alert("You must enter at least one stock number and supplier name.");
} else {
var cToAddr = "dealtickets@website.com";
var cCustomer = this.getField("tradingname").value;
var cDate = this.getField("dealdate").value;
var cSubLine = "Deal Ticket Submission" + " - " +cCustomer + " - " +cDate;
var cBody = "I have checked the attached deal ticket and am happy that all the information is correct ready for it to be processed on the system.";
this.mailDoc({bUI: true, cTo: cToAddr, cSubject: cSubLine, cMsg: cBody});
}
Copy link to clipboard
Copied
You can do it like this:
var ccAddresses = [];
if (this.getField("Contract Hire").valueAsString=="Yes") ccAddresses.push("address1@server.com");
if (this.getField("Service Contract").valueAsString=="Yes") ccAddresses.push("address2@server.com");
this.mailDoc({bUI: true, cTo: cToAddr, cCc: ccAddresses.join(";"), cSubject: cSubLine, cMsg: cBody});
Copy link to clipboard
Copied
Thats perfect
Thank you very much
Copy link to clipboard
Copied
Hello Try67,
Im sorry to bother you again, but my cc email has evolved slightly.
The code you gave me works perfectly well, but i have been asked to add another email based on a drop down selection being used.
There could be a combination of the radio buttons above being used and also a drop down list to add another email
This is the code i have on the submit button regarding the emails
var cToAddr = "dealtickets@server.com";
var ccAddresses = [];
if (this.getField("contracthire").valueAsString=="Yes") ccAddresses.push("email.1@server.com");
if (this.getField("servicecontractbutton").valueAsString=="Yes") ccAddresses.push("email.1@server.com", "email.2@server.com");
if (this.getField("extwarrantya").value=="smo") ccAddresses.push("email.2@server.com");
var cCustomer = this.getField("tradingname").value;
var cDate = this.getField("dealdate").value;
var cSubLine = "Deal Ticket Submission" + " - " +cCustomer + " - " +cDate;
var cBody = "I have checked the attached Deal Ticket and am happy that all the information is correct.\n\nI understand that the Deal Ticket will be returned if any information is missing or incorrect and WILL NOT be processed until the information is corrected and the Deal Ticket re-submitted";
this.mailDoc({bUI: true, cTo: cToAddr, cCc: ccAddresses.join(";"), cSubject: cSubLine, cMsg: cBody});
contracthire and servicecontractbutton are the radio buttons used which work perfectly well. However extwarrantya is a drop down list and i need email.2 to be added to the cc line if any option other than the default is selected.
Is this possible?
Copy link to clipboard
Copied
Change this line:
if (this.getField("extwarrantya").value=="smo") ccAddresses.push("email.2@server.com");
To:
if (this.getField("extwarrantya").value!=this.getField("extwarrantya").defaultValue) ccAddresses.push("email.2@server.com");
Copy link to clipboard
Copied
Thank you Try67,
That works perfectly but i now have the issue that if the service contract button is on yes the email.1 and email.2 addresses are added to the cc line, but alos of the extwarrantya is not on defualt the email.2 is added again giveing a cc line of email.1; email.2; email.2
Is there a way of getting to code to remove a duplicated email address?
Copy link to clipboard
Copied
There is, but you can achieve it more easily using a better structure of your if-else statements, like this:
if (this.getField("servicecontractbutton").valueAsString=="Yes") ccAddresses.push("email.1@server.com", "email.2@server.com");
else {
if (this.getField("contracthire").valueAsString=="Yes") ccAddresses.push("email.1@server.com");
if (this.getField("extwarrantya").value!=this.getField("extwarrantya").defaultValue) ccAddresses.push("email.2@server.com");
}
Copy link to clipboard
Copied
Hi Try,
That yields the same issue as there will be times the servicecontractbutton and the extwarrantya will both be in use
which adds the email.2 twice
Copy link to clipboard
Copied
Sorry my bad i hadnt enclosed the else if in its own {}

