Skip to Content

Dynamically populating the email address of an email button on a SAP Interactive Form

This is another question I get quite frequently. I’m posting here an extended description so that I can point to this blog if I get this asked again 😉

For the implementation of an offline scenario based on SAP Interactive Forms you have a couple of options how to submit data back to the SAP backend (e.g. HTTP post, email or Web Services).

In this blog I’m talking about submitting data via an email submit button. The scenario is basically as follows. An external person has to be included into a business process (e.g. to correct existing data or add additional data or to confirm something). This person has no access to the SAP system through SAPGUI or a portal. To include this person into the process an Interactive Forms is created in the SAP backend. The form is pre-populated with all relevant information and automatically sent out (e.g. via Business Communication Service). The person receives the Interactive Form as an attachment of an email, works with it and when finished presses the email submit button. Then the desktop email client is used to send back data (either as PDF or XML data depending on the selected option during form design).

I create the email button on the form based on the standard button. I drag and drop the button onto the form and then take a look at the properties. In the “field” tab of the object palette you can find the “control type”. I just set it to “submit”. Doing this I get an additional tab called “submit”. This tab contains a field where you can enter the “Submit to URL”. If you want to submit data via email you have to use an “mailto:” URL.

The email address shouldn’t be contained in the form template. It should be data driven so that it can be changed without touching the template. So let’s assume that the email address is contained in the form data (e.g. in a node that is not bound to any field on the form).

First of all we have to find out where the URL is stored in the template. The XFA Specification helps us here (see also my Useful documentation for developing Interactive Forms). It tells us that a submit button has a node “event”. This node has another subnode called “submit” and this node has a property called “target”. To dynamically set the submit-to URL we have to script against this property.

To access the “target” property of the email button in JavaScript we have to use the function resolveNode. You can use the following JavaScript line to set the URL of a submit button (for example in the initialize event):

xfa.resolveNode(“form1.page1.Button1.#event.#submit”).target = “mailto:”+$record.emailaddress.value;
this.resolveNode(“#event.#submit”).target = “mailto:”+$record.emailaddress.value;

The second resolveNode call is relative to the node where the call is made (in this example the initialize event of “Button1”). The SOM expression $record.emailaddress is used to access the data node (these expressions are case sensitive!).

You could do even more fancy stuff like setting the subject and a body text for the email.

xfa.resolveNode(“form1.page1.Button1.#event.#submit”).target = “mailto:”+$record.emailaddress   +”?subject=”+$record.emailsubject+”&body=”+$record.emailbody;

You can take a look at the mailto RFC for other parameters.

Note: The email client has to support MAPI. Otherwise this will not work properly.

You must be Logged on to comment or reply to a post.
  • Hi,

    First , what a great blog, it's help me a lot.

    I got a problem when i try to do the same on my forms . The e-mail adress is empty or there's an error when i press the button .

    I works on ECC5.0 with WAS 6.40 . and here is my javascript code on event initialize at Client side.

    this.resolveNode("#event.#submit").target= "mailto:"+$record.MAIL_ADRESS;

    Can you help me ?

    • Hi,

      hard to say without looking at the form. Did you check that the button is of the control type "submit"? Is the scripting language JavaScript? You could also check out my blog about accessing data nodes.


      • Hi Juergen,

        Thanks for your answer . I try with 2 buttons ( one type 'Send by Mail' and one "standard" with control type submit . The language is JAVASCRIPT and i try it while saying it's on client and or server side ( i try the 3 possibilities ) .

        For the "mail button" when i click on it there's an error of "argument" and on the others one i don't get any adress.

        If you want i can send it by mail . Let me know.

        Best regards.

  • It is better to use the layout:ready event instead of the initialize event.

    And here's a correction:
    To acces a data node you have to use
    $record.emailaddress.value. I missed the ".value" in my blog.


  • Juergen,
      Thanks for making our lives easy with your blogs on working with Adobe forms. I tried the code given in this blog and it works as you have mentioned. But  the mail attaches as unknown.xdp. How do I make sure that it takes a proper name here. Also when the recipient receives the attachment how can he open the XDP file  to see the layout&data in the Adobe Reader. Appreciate your inputs here.


    • Hi Surya,

      regarding the file name: it is currently impossible to set the file name.
      Regarding the attachment type you have to specify which type you want to have. In your case I think you set the "submit format" to XDP. This is on the "submit" tab of the object palette. Simply set it to PDF for example.


  • Hi Juergen,

    I am using the below code - xfa.resolveNode(“form1.page1.Button1.#event.#submit”).target = “mailto:”+$record.emailaddress   +”?subject=”+$record.emailsubject+”&body=”+$record.emailbody;

    While using the code its appending the body details in the subject. Its concatenating the body also.

    Result is :

    Subject&body=Body details


    Please suggest me how to avoid the same.

    Thanks in advance.