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.
- Before we start defining the relevant scenario, please configure your B1i Development environment as explained at Unit -4 Development environment of Open SAP Course – In Action – Integration Framework for SAP Business One.
- Basic knowledge of SQL
- Knowledge of XML/XSLT
- SAP Business One knowledge is useful
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).
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.
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 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
#SELECT E_Mail FROM OCRD WHERE CardCode = '$VendorCode'
- 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>firstname.lastname@example.org</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>
- 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.
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!