Skip to main content
Kibang
Known Participant
September 14, 2022
Answered

Javascript and submit form actions

  • September 14, 2022
  • 1 reply
  • 2511 views

Hello all,

I am a relative newbie when it comes to this, so any help would be greatly appreciated. I have created a form where a user fills out a form, clicks submit for approval, then it will send the form in an email to the person that has to approve it. No issue there. They fill it out click on 'submit for approval,' and the form is attached to an email that opens up, ready to enter in the approver's email address. 

Once the approver receives it and opens it, they fill out the remaining fields of the form (hidden until the user clicks on 'submit for approval', then click on 'submit approved form.' The form is supposed to get attached to an email that opens up, and it is supposed to be prepopulated with email addresses of two recipients, plus the email address of the division that is chosen in an dropdown field (Division Email) for the approver. 

What is happening is that an email window opens with the form attached, but it is not pre-populated with the two designated email addresses or the chosen email address. The recipient field is empty.

I have set up actions where the javascript runs first, then submit form, which is just 'mailto:' in the URL field. I feel like I am close, but do not know what that crucial step is to get the javascript to run first then open up the submit form with the designated email adresses pre-populated.

Thank you in advance!

 

Here is the javascript I used:

 

if (this.getField("Division Email").valueAsString == "traveldesk@company.com")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com; account.rep@travelcompany.com; traveldesk@company.com;",
cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});


else if (this.getField("Division Email").valueAsString == "travelcp@company.com")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com; rachel.kronlein@corporatetraveler.us; travelcp@guttmacher.org;",

cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});


else if (this.getField("Division Email").valueAsString == "traveldev@guttmacher.org")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com; account.rep@travelcompany.com; traveldev@company.com;",

cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});

else if (this.getField("Division Email").valueAsString == "travelpres@company.com")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com; account.rep@travelcompany.com; travelpres@company.com;",

cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});

else if (this.getField("Division Email").valueAsString == "travelpp@company.com")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com; account.rep@travelcompany.com; travelpp@company.com;",

cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});

else if (this.getField("Division Email").valueAsString == "travelresearch@company.com")

this.mailDoc({
bUI: true,
cTo: "traveldesk@company.com;  account.rep@travelcompany.com; travelresearch@company.com;",

cSubject: "Travel authorization form " + this.getField("text1 + text2").valueAsString
});

 

 

 

Ki

This topic has been closed for replies.
Correct answer try67

try67, thank you for your post. Unfortunately, it is still not opening up an email. It looks like nothing is happening. I tried another way, but the same 'nothing' happens

 

// 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 to match the code below

var cToAddr = "traveldesk@company.com;accountrep@servicecompany.com"

 

// First, get the client CC email address

var cCCAddr = this.getField("DivisionEmail").value;

 

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

var cemail = this.getField("text3").value;

if(cemail != "")cCCAddr += ";" + cemail;

 

 

// Set the subject and body text for the email message

var cSubLine = "Approved Travel Authorization Form"

var cBody = "Thank you for submitting your form.\n" + "Save the filled form attachment for your own records"

 

// Send the entire PDF as a file attachment on an email

this.mailDoc({bUI: true, cTo: cToAddr, cCc: cCCAddr, cSubject: cSubLine, cMsg: cBody});

 

 


Are there any error messages in the JS Console when you click the button? Can you share the file with us?

 

1 reply

Kibang
KibangAuthor
Known Participant
September 14, 2022

Here is a screenshot of the action on the 'submit approved form'

Nesa Nurani
Community Expert
Community Expert
September 14, 2022

You can't use this: this.getField("text1 + text2").valueAsString

use like this:

this.getField("text1").valueAsString+this.getField("text2").valueAsString

Kibang
KibangAuthor
Known Participant
September 14, 2022

Nesa,

Thank you for the prompt reply! I changed that part of the script, but nothing seems to happen when I click on 'submit approved form.' I tried to add an action (run a javascript) with mouse up. What am I missing here?

Ki