Copy link to clipboard
Copied
I have a form created many years ago by someone alot smarter than I. They used Adobe Acrobat to make a form and added a button that used Java script to email the form to a group. I have been able to get the script narrowed down to what I need other than I would like for it to add a field from the form, memberid, in the subject line of the email. Right now the Java code it this:
// submit the form
if (bContinue) {
var submitURL;
if (app.viewerVersion < 9.0)
submitURL = "mailto:djackson@*********.com?subject=Submitting Completed Form <memberid>&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
else
submitURL = "mailto:djackson@*************.com?subject=Submitting%20Completed%20Form%20<memberid>&body=Instructions%20to%20add%20this%20form%20to%20a%20response%20file:%0A1.%20Double-click%20the%20attachment.%0A2.%20Acrobat%20will%20prompt%20you%20to%20select%20a%20response%20file.&ui=false";
currentDoc.submitForm({
cURL: submitURL,
cSubmitAs: "PDF"
});
}
All it is doing is putting <memberid> in the subject line, not the actual number from the memberid field in the form. Any thoughts? is this even possible?.
Copy link to clipboard
Copied
Sure is. Change the submitURL variable definition to:
submitURL = "mailto:djackson@*********.com?subject=Submitting Completed Form "+this.getField("memberid").valueAsString+"&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
I think you have a mistake in it, though. The "&ui=false" part should not be a part of this string, it's a separate parameter.
Also, it won't work. You can't specify this parameter as false, unless the code is located in a doc-level script.
Copy link to clipboard
Copied
Sure is. Change the submitURL variable definition to:
submitURL = "mailto:djackson@*********.com?subject=Submitting Completed Form "+this.getField("memberid").valueAsString+"&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
I think you have a mistake in it, though. The "&ui=false" part should not be a part of this string, it's a separate parameter.
Also, it won't work. You can't specify this parameter as false, unless the code is located in a doc-level script.
Copy link to clipboard
Copied
And the submitForm method doesn't even have such a parameter...
Copy link to clipboard
Copied
let me paste the entire thing, I have been going in circles on this for hours..... Any advice is much appreciated. Here it is in it's entirety.... PS pretty sure 99% of it is redundant and not needed but I have no clue what I am doing...
//@@SUBMITURL "mailto:djackson@********.com?subject=Submitting%20Completed%20Form%20(member)&body=Instructions%20to%20add%20this%20form%20to%20a%20response%20file:%0A1.%20Double-click%20the%20attachment.%0A2.%20Acrobat%20will%20prompt%20you%20to%20select%20a%20response%20file.&ui=false"
/**************************************************************
AdobePatentID="B643"
**************************************************************/
var AdobePatentID = "AdobePatentID=\"B643\"";
// initiate some constants
var METADATA_ANNOT_NAME = "adhocFormState";
var PROP_RESPONDENT_NAME = "respondentName";
var PROP_RESPONDENT_EMAIL = "respondentEmail";
var currentDoc;
if (typeof(xfa) == "object")
currentDoc = event.target;
else
currentDoc = this;
// Only on Viewer/Reader older than 9.0, we'll do the following tasks.
var bAnonymous = true;
var bContinue = true;
if (app.viewerVersion < 9.0) {
// show the email/name dialog if not anonymous
if (!bAnonymous && !currentDoc.dynamicXFAForm) {
var result = currentDoc.askUserIdentity(currentDoc);
if (result == null)
bContinue = false;
else {
var annot = currentDoc.getAnnot(0, METADATA_ANNOT_NAME);
if (annot != null) {
var arrProps = new Array();
arrProps = annot.contents.split(";");
currentDoc.setProperty(arrProps, PROP_RESPONDENT_NAME, result.name);
currentDoc.setProperty(arrProps, PROP_RESPONDENT_EMAIL, result.email);
annot.contents = arrProps.join(";");
}
}
}
// show the select client dialog
if (bContinue) {
var result = currentDoc.askEmailClient(currentDoc);
if (result == null)
bContinue = false;
else if (!result.send) {
app.execMenuItem("SaveAs");
bContinue = false;
}
}
}
// submit the form
if (bContinue) {
var submitURL;
if (app.viewerVersion < 9.0)
submitURL = "mailto:djackson@**********?subject=Submitting Completed Form (memberid)&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
else
submitURL = "mailto:djackson@**********.com?subject=Submitting%20Completed%20Form%20wtite(memberid)&body=Instructions%20to%20add%20this%20form%20to%20a%20response%20file:%0A1.%20Double-click%20the%20attachment.%0A2.%20Acrobat%20will%20prompt%20you%20to%20select%20a%20response%20file.&ui=false";
currentDoc.submitForm({
cURL: submitURL,
cSubmitAs: "PDF"
});
}
Copy link to clipboard
Copied
Did you try what I suggested?
Copy link to clipboard
Copied
I did, I think, but it did not do anything after that, and then I saw where you said you thought I might have an error so I decided to provide the entire thing in case that helped explain why the false statement was there. Again, I did not make it and not sure why any of it is there... This is what I have now:
//Set the member id:
var member = getField("MemberAccountNumber").valueAsString;
//@@SUBMITURL "mailto:djackson@******.com?subject=Submitting%20Completed%20Form%20(member)&body=Instructions%20to%20add%20this%20form%20to%20a%20response%20file:%0A1.%20Double-click%20the%20attachment.%0A2.%20Acrobat%20will%20prompt%20you%20to%20select%20a%20response%20file.&ui=false"
/**************************************************************
AdobePatentID="B643"
**************************************************************/
var AdobePatentID = "AdobePatentID=\"B643\"";
// initiate some constants
var METADATA_ANNOT_NAME = "adhocFormState";
var PROP_RESPONDENT_NAME = "respondentName";
var PROP_RESPONDENT_EMAIL = "respondentEmail";
var currentDoc;
if (typeof(xfa) == "object")
currentDoc = event.target;
else
currentDoc = this;
// Only on Viewer/Reader older than 9.0, we'll do the following tasks.
var bAnonymous = true;
var bContinue = true;
if (app.viewerVersion < 9.0) {
// show the email/name dialog if not anonymous
if (!bAnonymous && !currentDoc.dynamicXFAForm) {
var result = currentDoc.askUserIdentity(currentDoc);
if (result == null)
bContinue = false;
else {
var annot = currentDoc.getAnnot(0, METADATA_ANNOT_NAME);
if (annot != null) {
var arrProps = new Array();
arrProps = annot.contents.split(";");
currentDoc.setProperty(arrProps, PROP_RESPONDENT_NAME, result.name);
currentDoc.setProperty(arrProps, PROP_RESPONDENT_EMAIL, result.email);
annot.contents = arrProps.join(";");
}
}
}
// show the select client dialog
if (bContinue) {
var result = currentDoc.askEmailClient(currentDoc);
if (result == null)
bContinue = false;
else if (!result.send) {
app.execMenuItem("SaveAs");
bContinue = false;
}
}
}
// submit the form
if (bContinue) {
var submitURL;
if (app.viewerVersion < 9.0)
submitURL = "mailto:djackson@*******.com?subject=Submitting Completed Form "+this.getField("memberid").valueAsString+"&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
else
submitURL = "mailto:djackson@********.com?subject=Submitting Completed Form "+this.getField("memberid").valueAsString+"&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
currentDoc.submitForm({
cURL: submitURL,
cSubmitAs: "PDF"
});
}
Copy link to clipboard
Copied
So after you made the change and clicked the button nothing happened? If so, then check the JS Console for error messages.
Copy link to clipboard
Copied
sorry for disappearing, Had to get to the school for my son's parent teacher conference. Back to work and will be trying the debug now. Will update you soon
Copy link to clipboard
Copied
ok error is "typeError: this.getfield(...) is null 59:FieldLMouse Up
Copy link to clipboard
Copied
line 59 reads:
submitURL = "mailto:djackson@****.com?subject=Submitting Completed Form "+this.getField("memberid").valueAsString+"&body=Instructions to add this form to a response file:\n1. Double-click the attachment.\n2. Acrobat will prompt you to select a response file.&ui=false";
so looks like progress, let me verify the properties of that field
Copy link to clipboard
Copied
That means there's no field in your file called "memberid". Check the spelling and remember it's case-sensitive.
Copy link to clipboard
Copied
I dont know if you are male or female but if you were here I would kiss you. That was it, I did not know it was case sensitive!!!! WOW. Thank you so much!!!! Now on to the next form, they want this one to pull numbers from fields and total them... I hate this stuff so much!!! lol
Copy link to clipboard
Copied
from what I can see the field is ok

