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

Javascript and submit form actions

Community Beginner ,
Sep 14, 2022 Sep 14, 2022

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

TOPICS
PDF forms
2.1K
Translate
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
1 ACCEPTED SOLUTION
Community Expert ,
Sep 14, 2022 Sep 14, 2022

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

 

View solution in original post

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

Ki26117959lyhb_0-1663177706160.pngexpand image

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

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

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

use like this:

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

Translate
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 ,
Sep 14, 2022 Sep 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

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

Remove the "Submit a form" command. The code takes care of that for you.

Also remove the spaces after each semi-colon in the list of emails under cTo.

 

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

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

 

 

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

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

 

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

I copied code from other users. I am not getting any errors when I revise the script with my information. Could I send you the script offline? 

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

"Offline"? You want to send it by post? ... I think you mean privately.

If so, then yes, you can send it to [try6767 at gmail.com].

Translate
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 ,
Sep 14, 2022 Sep 14, 2022

Sorry, I meant private email. I just sent you the scripts I tried

Translate
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 ,
Sep 15, 2022 Sep 15, 2022

I tried to get this working, but I do not know enough to resolve the problems, even with looking at the java console (thanks, Try67!), so I have decided to just insert a submit form action with two pre-populated emails and a disclaimer to tell the authorizer to include another email address when sending on. The question I have now is, how do I customize the default text that is included in the email (Form Returned: Travel authorization form (003).pdf

The attached file is the filled-out form. Please open it to review the data)? From what little I know, it seems I would have to insert a script, which would have to include the submit form function as well, but like I said, I am a novice at this. Any input would be greatly appreciated.  

Translate
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 ,
Sep 15, 2022 Sep 15, 2022

just to clarify, the disclaimer is in the form itself, and not in the generated email with attachment

Translate
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 ,
Sep 16, 2022 Sep 16, 2022
LATEST

Try67 helped me to understand some basics regarding Javascript, and I was able to figure out where I needed to make changes to fix the script. Thank you, Try67

Translate
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