Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.
SOLVED

Need help with Javascript automated e-mail

Avatar

Level 2

I am trying to modify a form to add a button that takes values from fields that will be populated by the user and then send an email using these fields

currently I have the following script:

var A = xfa.resolveNode("topmostSubform.Page1.Work_Order__").rawValue;
var B = xfa.resolveNode("topmostSubform.Page1.NOMENCLATURE").rawValue;
var PPC = xfa.resolveNode("topmostSubform.Page2.Email_Address_PPC").rawValue;
var sub = "Work Order Created";
var msgBody = "The Work Order, " + A + "\n for the " + B + " program has been created";
    app.mailMsg({
        bUI: false,
        cTo: PPC,
        cSubject: sub,
        cMsg: msgBody,
        });

Thanks for your help,

John

1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi John,

Your script does not look too wrong. Here is our generic script:

var vEmail = "email@address.com";

var vSubject = "A Subject for your email";

var vBody =  "Put your body message here...";

event.target.app.mailMsg({

     bUI: true,

     cTo: vEmail,

     cSubject: vSubject,

     cMsg: vBody

});

Try placing "event.target." before the app.mailMsg. Also you don't need the xfa.resolveNode, if the objects, pages and subofrms are named.

Hope that helps,

Niall

View solution in original post

11 Replies

Avatar

Correct answer by
Level 10

Hi John,

Your script does not look too wrong. Here is our generic script:

var vEmail = "email@address.com";

var vSubject = "A Subject for your email";

var vBody =  "Put your body message here...";

event.target.app.mailMsg({

     bUI: true,

     cTo: vEmail,

     cSubject: vSubject,

     cMsg: vBody

});

Try placing "event.target." before the app.mailMsg. Also you don't need the xfa.resolveNode, if the objects, pages and subofrms are named.

Hope that helps,

Niall

Avatar

Level 2

I am also trying to use the same script to create an e-mail when a document is electronically signed. What event would I use in order to create the e-mail?

Avatar

Level 10

Hi John,

You could try the postSign event, however I suspect that this will fire even if the user cancels the signing that they had initiated. Give it a try.

There is a way to way to look at the status of a signature field, but from memory it is involved and I can't remember the details. I can't dig it out now, but will try and follow up later.

Niall

Avatar

Level 2

I tried adding a postSign event (it isn't a normal option), but when I open the file I get an error that postsign is not a valid event

John

Avatar

Level 10

John,

The postSign event was introduced in XFA Specification 2.8: http://partners.adobe.com/public/developer/xml/index_arch.html

This means that the event is only available in LC Designer ES2, BUT also it will only work in Acrobat/Reader version 9.0 or above. This would mean that in LC Designer, File > Form Properties > Defaults you would need to set the target version to 9.

If this is not acceptable, I have located and updated the example I have for earlier versions: http://assure.ly/m8mN0m

Hope that helps,

Niall

Avatar

Level 2

Sadly I don't have control over the version of Adobe.

I tried using the script from your example to check if the form has been signed, but nothing happens when I try it out. I have noticed that even though my fields are named, I still have to use xfa.resolveNode to get their values. If you could give me any advice on what could be wrong with this script I'd appreciate it.

var oState = event.target.getField("topmostSubform.Page1.PPC").signatureValidate();

if (oState != 0)
{
xfa.host.messageBox("You have signed the form. \n\nPlease click OK. \n\nThank you!", "Form Submitted", 0, 0);

}
else
{
xfa.host.messageBox("You have signed the form. \n\nPlease click OK. \n\nThank you!", "Error submitting this form", 0, 0);
}

Thanks,

John

Avatar

Level 10

John,

There is a discussion on xfa.resolveNode here: http://forums.adobe.com/message/3666568#3666568.

What event are you using for the script (and in what object)?

Also are you getting an error? When viewing the form in Acrobat press Control+J to open the JavaScript Console. This may show up errors as you interact with the form.

There is very little difference in the messageBox message. Only the title changes. Is this correct?

Niall

Avatar

Level 2


TypeError: event.target.getField("topmostSubform.Page1.PPC").signatureValidate is not a function
1:XFA:topmostSubform[0]:Page1[0]:Test_Button[0]:click

Avatar

Level 10

Hi John,

In our example we have the full/absolute reference to the signature field:

var oState = event.target.getField("form1[0].page1[0].SignatureField1[0]").signatureValidate();

Your root node is "topmostSubform", so would look like this:

var oState = event.target.getField("topmostSubform[0].Page1[0].PPC[0]").signatureValidate();

On the basis that the signature field is called PPC.

In relation to naming pages, Master Pages are automatically named with a capital, eg "Page1". Becuase of this I would always use a lowercase "p" when naming the design pages, eg "page1".

It just helps to keep things separate.

Laslty check that the language is set to JavaScript.

Come back if that doesn't work,

Niall

Avatar

Level 2

alright I'm almost done.

Now I get the error:


SyntaxError: missing } after property list
14:XFA:Main_Form[0]:Page1[0]:Test_Button[0]:click

here is my script


var oState1 = event.target.getField("Main_Form[0].Page1[0].PPC[0]").signatureValidate();
var oState2 = event.target.getField("Main_Form[0].Page1[0].ENG[0]").signatureValidate();
var oState3 = event.target.getField("Main_Form[0].Page1[0].Branch[0]").signatureValidate();
var oState4 = event.target.getField("Main_Form[0].Page1[0].Division[0]").signatureValidate();

if (oState4 != 0)
    {
    var A = xfa.resolveNode("Main_Form.Page1.Work_Order__").rawValue;
    var B = xfa.resolveNode("Main_Form.Page1.NOMENCLATURE").rawValue;
    var sub = "Work Order Approved";
    var msgBody = "The Work Order, " + A + " for the " + B + " program has been approved";
    event.target.app.mailMsg({
        bUI: true,
        cTo: XX@navy.mil,
        cSubject: sub,
        cMsg: msgBody,
        });
    }

if (oState3 != 0)
    {
    Email_Division.execEvent("click");
    }
   
if (oState2 != 0)
    {
    Email_Branch.execEvent("click");
    } 

if (oState1 != 0)
    {
    Email_Engineer.execEvent("click");
    }

else
    {
    var A = xfa.resolveNode("Main_Form.Page1.Work_Order__").rawValue;
    var B = xfa.resolveNode("Main_Form.Page1.NOMENCLATURE").rawValue;   
    var PPC = xfa.resolveNode("Main_Form.Page2.Email_Address_PPC").rawValue;
    var sub = "Work Order Created";
    var msgBody = "The Work Order, " + A + " for the " + B + " program has been created";
        event.target.app.mailMsg({
              bUI: true,
            cTo: PPC,
            cSubject: sub,
            cMsg: msgBody,
        });
    }

Avatar

Level 10

Hi John,

Looking at the script I suspect that the problem is the extra comma after cMsg: msgBody,

There is a syntax checker in the Script Editor that when clicked shoued highlight any errors.

Also you may want to edit your previous post, to remove the email address.

Hope that helps,

Niall