Skip to Content
Technical Articles
Author's profile photo Balakumar Viswanathan

B1if – Send email to Customer when an Invoice is added – Part II

Back to Part-I

Part II: Dynamic details & basic validations


  • Send an email with dynamic details.
  • Basic validations for
    • SMTP Server, and
    • Customer’s email id
  • In case of missing SMTP or Customer email, send an alert to SAP Business One user (creator of Invoice).
  • Send email only while adding an AR Invoice.

If you guys configured and tested properly (the first part) then you would have been noticed that you will get an email even while an AR Invoice is updated 😛  No worries, we will handle that bug (sort of) here.


When an AR Invoice is added at SAP Business One, automatically an email will be sent after basic validation to respective customer’s email id with dynamic details.

If the scenario (of Part-I) is activated, please deactivate since we are going to modify the same scenario step. Alternatively, you can copy the existing scenario step.

Following atoms are already used at Part-I

  • Call SQL atom
  • XSL Transformation atom
  • Send email atom

In addition to the above, we are going to use the following atoms in this part of the tutorial.

  • Control Structure Atom (Branch & Unbranch)
    • Path configuration
    • Otherwise configuration


Step 1: Add Conditional Processing Control structure – Transaction type

At step processing, add Conditional Processing Control Structure (refer the image below)

Above step will add a branch with a For-Each loop. In our example, we don’t need For-Each, thus delete the “for-each” path.

Switch off the “always processing” by toggling the radio button, refer the image below:

As per the scenario (chart) our aim to check whether the AR Invoice is added or not. If added, we need to further process else “no action” will be taken and has to exit the step.

Configure the Path as per below image

 xPath Expression is

/*[/vpf:Msg/vpf:Body/vpf:Payload[./@Role='T']/Event/b1e:b1events/b1e:b1event/b1e:transactiontype = 'A']

Step 2: Add Conditional Processing Control structure – SMTP server

In order to check the SMTP server exists, we need an XSL Transformation atom to retrieve the SMTP server name. In this example, it is assumed that if the SMTP server name exists then the definitions are correct and if not, SMTP definition is incomplete. You can feel free to modify the definitions and conditions for this Control structure.

Thus, add an XSL Transformation atom after the [1 Get Email] SQL call atom, and add the following transformation code.

<xsl:template name="transform">
   <xsl:variable name="cdoc" select="document(&apos;/;)"></xsl:variable>
       <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpserver"></xsl:value-of>

Use the above XSL Transform atom result at the Path configuration.

xPath Expression for PATH is

/* [string-length(/vpf:Msg/vpf:Body/vpf:Payload[./@id='atom8']/host) != 0]

Step 3: Add Conditional Processing Control structure – Customer Email

Use the[1 Get Email] atom result at the Path configuration.

xPath Expression for PATH is

/*[string-length(/vpf:Msg/vpf:Body/vpf:Payload[./@id='atom1']/jdbc:ResultSet/jdbc:Row/jdbc:E_Mail) > 0]

Step 4: Move the atoms

Move both the [2 Prepare email] atom and “Send email” atom to the final branch path’s.

Tip: In order to move the atom, click the green box to select the desired atom to move (red color border visually confirms the selection is successful). Once selected, click the arrow at the desired place to move (in our example click the > at the Path atom).

Refer the image below:

Now, we have completed all the conditional control structures.

We need to add the SAP B1 alert message(s) and have to place the dynamic details at Email.

Step 5: Dynamic details for email

Modify the [2 Prepare email] atom as per the below XSL transform

<xsl:template name="transform">
            <xsl:variable name="cdoc" select="document(&apos;/;)"></xsl:variable>
            <xsl:variable name="DocDate">
                <xsl:value-of select="$msg/BOM/BO/OINV/row/DocDate"></xsl:value-of>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpserver"></xsl:value-of>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpPort"></xsl:value-of>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpuser"></xsl:value-of>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtppwd"></xsl:value-of>
                        <xsl:value-of select="vpf:Msg/vpf:Body/vpf:Payload[./@id=&apos;atom1&apos;]/jdbc:ResultSet/jdbc:Row/jdbc:E_Mail"></xsl:value-of>
                        <!-- optional - multiple elements allowed -->
                <subject> Sales Invoice - <xsl:value-of select="$msg/BOM/BO/OINV/row/DocNum"></xsl:value-of> is added
                <BodyPart filePath="" content-type="text/xml;charset=utf-8" content-id="" content-disposition="">
Sales invoice - <xsl:value-of select="$msg/BOM/BO/OINV/row/DocNum"></xsl:value-of> is created at SAP B1.
Document details:-
Invoice number:<xsl:value-of select="$msg/BOM/BO/OINV/row/DocNum"></xsl:value-of>
Invoice date:<xsl:value-of select="concat(substring($DocDate,7,2),&apos;-&apos;,substring($DocDate,5,2),&apos;-&apos;,substring($DocDate,1,4))"></xsl:value-of>
Invoice Amount:<xsl:value-of select="$msg/BOM/BO/OINV/row/DocTotal"></xsl:value-of>

Step 6: Define B1 Messages

Add “Send B1 Message” atoms after the both “otherwise” of Path Control structure.

Refer the screen shot below:

Configuration for [11 email msg] atom is:

xPath expression for User Code field is


Use the above xPath expression to send the alert message to the SAP B1 user who is creating the AR Invoice. Also, you can use static user code like #manager if you like to send the alert to “manager” user.

Configuration for [12 SMTP msg] atom is:

xPath expression for User Code field is


Step 7: Testing

Please refer the Step-6 Testing of this blog for how-to-activate scenario.

Upon successful activation of the scenario package, open your “Sender system” and create an AR Invoice.

Refer below the sample testing results & debug view for multiple scenarios

Scenario-1: SMTP and Customer email defined

Debug view displays the path taken by B1i (please follow the red arrow).

Scenario-2: SMTP is not configured

Debug view

Scenario-3: Email is not defined for Customer

Debug view:

This concludes the blog series.

Scope of improvement:

Following is the list (indicative and not exhaustive) of scope of improvement for this Scenario package.

  • Presenting the email body with HTML tags.
  • Sending the B1 Messages with details of the Invoice number.
  • Sending the email with attachments.
  • Instead of creating a control structure for the Transaction type, modifying the Email / B1 Message with the transaction type.
  • On success of “send email”, you may send B1 Message to the user with success message.
  • Based on the “send email” atom result, send a B1 Message to the user with success or failure message.
  • Extending the scenario package to handle other Document types.

Sample email for an AR Invoice updated with HTML formatting:

Hope the tutorial is beneficial to you guys and worth to read one 😛

Happy Integrating…!

Best Regards,

Balakumar Viswanathan

Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.