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

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

In the first part of two-part blog series, we are going to see a step-by-step guide on “how to send email to customer when an invoice is posted at SAP Business One database”.

In this part, we are going to send email with static text to Customer.

Prerequisites:

It is highly advised to complete the above said Open SAP course prior to start building this scenario.

If you are interested, you could also check this blog –聽B1if – first impression and basics.

Applications and versions used:

  • B1i Integration Framework – Version聽1.22.21 (ya, I know, there is version 2.0 too 馃槢 , let me try in another blog to make this same tutorial by using that version too, if time permits.)
  • SAP Business One 9.3 PL08
  • PaperCut v5.4.0 (Optional and used for Local SMTP server).

Scenario:

When an AR Invoice is created in SAP Business One, automatically an email will be sent to the respective customer’s email id.

Please note, error handling are not included in this tutorial. Thus, it assumes that the SMTP is configured at B1i and the Customer has the defined email id at Business Partner Master data.

How-to:

Step 1: Create a Scenario Package

After log in to B1i framework, create a new scenario package as per the image below.

Click ‘Save’ button.

Step 2: Create a Scenario Step:

Create a Scenario step (as per below image) and assign it to the scenario package created at Step 1.

In order to assign this step to the scenario package created at Step 1, click the browse button of “Scenario Package Identifier” and select the Scenario Package from the drop down list.

On clicking the Select button, you will get a pop-up message (refer the image below).

Click OK.

Click SAVE button.

Step 3: Define Inbound Channel for the step

Refer the below image to define the Inbound refer the image below.

Click SAVE button at “Scenario Step Design – INBOUND” screen.

Step 4: Define the Inbound Retrieval and Outbound for the step

Refer the below image.

Click the SAVE button to close and return to Scenario Step Design window.

Define your outbound as “void”.

For your reference, Scenario Step design should look this at this time 馃檪

For safer side, click the SAVE button at the above window.

Step 5: Processing

On clicking on Processing button, you will get a new pop-up window as below

Click the Arrow icon at the initial atom, choose “Call SQL” at New Flow atom and click “Add”.

Define the SQL atom as below image:

 

xPath for VendorCode variable is

/vpf:Msg/vpf:Body/vpf:Payload[./@Role='S']//BOM/BO/OINV/row/CardCode

SQL Statement:

#SELECT E_Mail FROM OCRD WHERE CardCode = '$VendorCode'

Clarifications/Explanations:

  • All values should be defined with preceding # character else it will be treated as xPath expression. Thus, make sure to have the # character for SQL statement.
  • At SysId of the SQL atom, either you can choose the SysId of your intended SAP Business One database or in general you can keep the Sender System.
  • It is advised to change the description of the SQL atom with a meaningful description. If you like to see your description in the flow then use [ ] characters to wrap your description. It is good to keep the atom number in the description for further references.
    • I’m keeping the description as [1 Get email] where 1 – is the atom number of this Call SQL atom.

Now your flow should look like this

Add a “Send email” atom by clicking the arrow button at our initially created atom [1 Get email]. Please don’t forget to click “YES” at the notification message that “Do you want to create a predecessor XSL transformation atom?”. This will add an XSL Transformation atom and a Send email atom.

At the Transformation atom, you will have the necessary structure required for send email atom. You will also see some commented lines. Just remove comment from the relevant lines else use the code below.

<xsl:template name="transform"> 
   <email>
            <xsl:variable name="cdoc" select="document('/com.sap.b1i.vplatform.ide/mode/mode.xml')"/>
            <connect>
                <host>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpserver"/>
                </host>
                <port>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpPort"/>
                </port>
                <user>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtpuser"/>
                </user>
                <password>
                    <xsl:value-of select="$cdoc/vpf:vPlatform/vpf:smtppwd"/>
                </password>
                <protocol>TLS</protocol>
            </connect>
            <envelope>
                <to>
                    <address>
                        <xsl:value-of select="vpf:Msg/vpf:Body/vpf:Payload[./@id='atom1']/jdbc:ResultSet/jdbc:Row/jdbc:E_Mail"/>
                    </address>
                </to>
                <cc>
                    <address></address>
                </cc>
                <bcc>
                    <address>
                        <!-- optional - multiple elements allowed -->
                    </address>
                </bcc>
                <from>fromemailid@test.com</from>
                <subject> Sales Invoice is created</subject>
                <BodyPart filePath="" content-type="text/html;charset=utf-8" content-id="" content-disposition="">
                    Sales invoice is created at SAP B1
                </BodyPart>
            </envelope>
        </email>
</xsl:template>

Note:

  • The address tag contains the result of our call SQL atom.
<address>
     <xsl:value-of select="vpf:Msg/vpf:Body/vpf:Payload[./@id='atom1']/jdbc:ResultSet/jdbc:Row/jdbc:E_Mail"/>
</address>
  • The xsl variable “cdoc” holds the path of the SMTP definition at B1i.
  • In order to define the SMTP at B1i, check the below image

 

  • I’m using local SMTP server for testing purpose, if you like to use your local SMTP server then check PaperCut here.

Your final processing flow should look like below

It is worth to mention that we don’t need to change the email atom as B1i itself configured the payload while adding this atom along with XSL Transformation atom.

Step 6: Testing

Activate the Scenario for testing.

At the Setup Wizard,

  • Click “All Activate” at “Scenario steps” page and click “Next” button.
  • Select your desired “Sender” system at “Senders and Receivers” page.
  • Click “Deploy”

Click “Activate” button at the “Scenario Package Setup” page.

Click “Activate” button on the following pop-up page. (Please wait for some 1-2 minutes for the scenario to get activated).

Upon successful activation of the scenario package, open your “Sender system” and create an AR Invoice. Please make sure the selected Customer has Email defined at Business Partner Master data.

If you are using PaperCut and local SMTP is configured, then you should receive an email as below

This concludes the Part-I tutorial.

What’s next:

In the next part of this series, we will learn how to send email with dynamic details (for instance details of AR Invoice) when a document is added and many more. So stay tuned!

Best Regards,

Balakumar Viswanathan

 

Link to Part – II

Assigned Tags

      5 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Gonzalo G贸mez Gonz谩lez
      Gonzalo G贸mez Gonz谩lez

      Congratulations for the post and thanks

      Author's profile photo Gustavo Wo
      Gustavo Wo

      Hi Balakumar,

      I followed the step-by-step and now when I add an invoice I get an error in Message Log:

       

      com.sap.b1i.xcellerator.XcelleratorException: XCE001 Nested exception: com.sap.b1i.bizprocessor.BizProcException: BPE001 Nested exception: com.sap.b1i.xcellerator.XcelleratorException: XCE001 Nested exception: com.sap.b1i.xcellerator.XcelleratorException: XCE001 Nested exception: java.io.IOException: 501 Command line too long or no terminating CRLF in line buffer

      Any idea how to solve this error?

      Thanks,

      Author's profile photo rajesh Madhav
      rajesh Madhav

      Hi Could you please let me know if there is any blog for the same process on version 2.0.

      Author's profile photo Saad Sabri
      Saad Sabri

      I've noticed that in some places when I used the <from> tag like this

      <from>ABC Company&lt;info@abccompany.com&gt;</from>

      It sends the email with the sender name as ABC Company. However, other times it would give me a syntax error like this :

      And then only accepts the from email as below

      <from>info@abccompany.com</from>

      is there a particular reason to this working some times and other times it would throw a syntax error? What is the workaround to this if you want to set the name of sender while sending an email?

      Author's profile photo Gonzalo G贸mez Gonz谩lez
      Gonzalo G贸mez Gonz谩lez

      after three years.... i麓ve tried to make it step by step..... but...

      In the part ....

      At the Transformation atom, you will have the necessary structure required for send email atom. You will also see some commented lines. Just remove comment from the relevant lines else use the code below

      How can i edit the atom to type the code you posted?

      At the final the image you posted....

      I think you missed the part that transform xform in 2 Prepare email

      thanks