Integration framework of SAP Business One Training

1 Integration framework of SAP Business One TrainingSolut...
Author: Melinda Shields
0 downloads 4 Views

1 Integration framework of SAP Business One TrainingSolution Architects Team February 2011 Creating new Web Services with the Integration framework

2 B1if Training: Creating new Web Services with B1ifThis document guides you through how to extend SAP Business One Mobile Solution, creating a new web service function with B1if, getting the document list by type, status and sale employee. Mainly focus on back-end side. After this chapter, you should be able to: Describe how to create Web Services with B1iC How to generate a scenario step for mobile package to extend service How to add additional call to SAP Business One in the process of scenario step How to implement the XSL to transform the result into the final response message How to test the Web Service hosted in B1iC

3 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

4 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

5 Integration Component Architecture OverviewFront-end Backend B1iC B1if B1i Framework Services Http(s) Xcelsius Mobile Company 1 …

6 SAP Business One Mobile Solution Architecture & Mobile Add-On PlatformMobile Add-On solution Standalone solution Mobile Add-On Framework Partner Add-On 1 Partner Add-On 2 Partner Add-On 3 Core Functionality Partner front-end Master data Inbox Workflow iPhone Client Web Service Web Service Partner contents for Add-ons Add-On management CRM Logistic Inbox Reporting Partner Content Device Admin Authentication Authorization Licensing Device Admin Authorization Authentication Licensing B1if SAP Business One SAP Provides Partner provides Benefits Front-end Core features (master data, workflow, etc. ) Add-on framework Back-end B1i platform Web service & Content Device Admin, authorization, authentication Licensing & Add-on management Front-end Add-Ons Custom Web Services for Partner Add-Ons hosted in B1if Only Focus on business logic No special knowledge for device is needed Bi-direction communication with B1 mobile core

7 The end-to-end process of extending SAP Business One Mobile SolutionDesign-Time Phase Run-Time Phase Create Partner Web Service (Back-End) Create Mobile Add-On (Front-End) Deploy and Run in Productive System Procedure: (Tool - B1if) Configure B1if as Vendor Mode (optional) Copy sap.B1Mobile package to your namespace (xxx) Analyze the business requirement and Design the web service for mobile Add-On Create and implement the partner web service step with B1if tool and Xml Editor Test the web service with B1if Export xxx.B1Mobile Package Procedure: (Web Development) SAP provides a mobile Add-On framework to simplify the mobile Add-On Development. Developing add-on web application to consume the web service. Deploy the add-on web app to B1if Test with browser (Safari, Chrome etc). Register Mobile Add-On in B1 Test in the iPhone Mobile App Procedure: Copy xxx.B1Mobile package with customer development into productive system. Reactivate xxx.B1Mobile in B1if Deploy the mobile Add-On web app folder in B1if Register Mobile Add-On in B1 Ready to run the mobile add-on in B1 iPhone app. Note: You can download Add-On sample code here. https://service.sap.com/~sapidb/ E Mobile Add-On development doesn’t require the iPhone SDK/environment and skill set of object C, but just web app development with HTML+JavaScript/VB script etc. SAP provides a set of interfaces and utility function to consume the web services. The Add-On web application should be deployed and hosted in B1if Note: This document will mainly focus on this part. SAP provides the default package sap.B1Mobile for back-end web services consumed by iPhone front-end application. Such web services can be possibly consumed by any devices as well.

8 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

9 Creating a new Web Service in B1if: Get the document list by doc type, status and owner for SAP Business One Mobile Solution Backend 3rd Party Application e.g. iPhone App B1if (Web Service Provider) SAP Business One Scenario Package: Copy sap.B1Mobile package Scenario Steps: xxx.GetDocList Input Parameters: Doc Table Name, Status, and Owner Processing: SQL Call via JDBC to retrieve the doc list Output: A document list with given doc type, status and owner Request to get the doc list by doc type, status and owner Request Retrieving documents list by doc type, status and owner Response Design Phrase - Exposing a scenario step in B1if as a web service method: sap.B1Mobile package is designed as a web service with several service methods, e.g. GetBpList Do not modify the sap.B1Mobile package in the sap namespace. Copy the package to your own namespace first Each service method is implemented as a scenario step in the scenario package. The logic of the service call is implemented with an additional SQL call to SAP Business One to get document list, add or update the document in the step flow. Run-Time Phase – Consuming the new web service method hosted by B1if : The web service is hosted as an activated scenario package, responsible for receiving the SOAP Request from external system and handing over to the target scenario step for process The relevant scenario step(web service method) will be triggered with the given SOAP request payload, retrieving the document list from SAP Business One with SQL call. The web service scenario step sends back the SOAP Response to the external system.

10 Inbound SOAP Request Service Method: ORDR O manager Service Method: GetDocList – Get the document list by document type, status and owner The service method is identified by the root tag of SOAP Request. Inbound Parameter: - TableName: Table name of the document. ORDR – Sales Order, OINV – A/R Invoices etc. Since all marketing documents share the table structure but with different table names, it can be reused to get all kind of marketing documents. - DocStatus: O – Open, C – Closed, “”(empty string) – All - userName: The current login user in mobile solution

11 Outbound SOAP ResponseAfter the final transformation in atom0.xsl, the outbound message should be like this: 1 C20000 Norm Thompson 14, $ :00:00.0 Output document header field: 1.DocEntry – Document Entry 2.CardCode – Bp Code 3.CardName – Bp Name 4.DocTotal – Document total amount, format as: number + currency 5.DocDate – Posting Date

12 Process: Retrieving the target doc list with SQL Call via JDBC1 Atom 1: SQL atom to retrieve the document list (to be added) 2 Atom 0: Final XForm atom to transform into outbound format(default step) Atom 1 - sql Call: Retrieving the doc list with sql call via JDBC SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM ORDR WHERE DocStatus = ‘O’ -Output fields of document: DocEntry, Bp Code, Bp Name, Posting Date, Total Amount. -Table [ORDR] will be replaced with variable $TableName from inbound parameter -DocStatus ‘O’ will be replaced with variable $DocStatus from inbound parameter Atom 0 – Final: Final transformation Always the default last step to transform the message into outbound format with atom0.xsl (to be implemented with xml editor later)

13 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

14 Deactivate and copy sap.B1Mobile packagePath: Scenarios/Control 1 Uncheck sap.B1Mobile package to deactivate 2 Copy package to your namespace xxx Note: Do not change the sap.B1Mobile package in the sap namespace. Copy the sap.B1Mobile scenario package to your own namespace. Scenario Packages cannot be copied in active mode, only in design mode. 1

15 Scenario Step Design: xxx.GetDocListPath: Scenarios/Step Design 1 Type GetDocList as Scenario Step Identifier. Prefix will be automatically added. 2 Choose the Scenario Package Identifier as xxx.B1Mobile 3 Click Save Button 4 Click Inbound Button 1 2 4 3 Note: The example above shows the GetDocList step added to the B1Mobile package in the sap namespace. This is just an example and you should add the new step to the B1Mobile package in your namespace.

16 Scenario Step Design: xxx.GetDocList: Inbound (2/3)Path: Scenarios/Step Design/Working Step/[Inbound] Identification method and trigger Identification method as root tag and identifier as root tag name. In our case, the SOAP Request body should be like: ……. Root tag in SOAP request will trigger the process of scenario step – xxx.GetDocList

17 Scenario Step Design: xxx.GetDocList: Inbound (1/3)Path: Scenarios/Step Design/Working Step/[Inbound] 1 Click on Channel 2 Using the ellipsis button (…) select Web Service Call as Inbound Type 3 Using the ellipsis button (…) select Synchronous as Process Mode 4 Using the ellipsis button (…) select Call as Process Trigger 5 Using the ellipsis button (…) select Root Tag as Identification Method 6 Input GetDocList as Identifier 7 Input xmlns:b1mb="http://tempuri.org/" as Identification namespace, defined by SAP for mobile package. 8 Click Save 9 Click Close 1 2 3 4 5 6 7 8 9

18 Scenario Step Design: xxx.GetDocList: Inbound (3/3)Path: Scenarios/Step Design/Working Step/[Inbound] 1 Click on Retrieval 2 Click Save 3 Click Close 1 Retrieval as Handover, B1if will decide how to retrieve the inbound message 2 3

19 Scenario Step Design: xxx.GetDocList: OutboundPath: Scenarios/Step Design 1 Click Outbound Button 2 Choose Outbound Channel as unknown 3 Click Save Button 4 Click Close Button 1 Outbound is unnecessary for synchronous call 2 3 4

20 Scenario Step Design: xxx.GetDocList: Processing(1/4)Path: Scenarios/Step Design 1 Click Processing Button 1 By default all scenario steps have one xform atom (called final) associated with an xslt file for final transformation.

21 Scenario Step Design: xxx.GetDocList: Processing(2/4)Path: Scenarios/Step Design/Working Step/[Processing] 1 Click on triangle icon to add a new atom 2 Select Call SQL as new Flow Atom 3 Click Add Button 4 Click Close 1 2 3 4

22 Scenario Step Design: xxx.GetDocList: Processing(3/4)Path: Scenarios/Step Design/Working Step/[Processing] 1 Click on pen icon to edit sqlCall atom 2 Select #B1 System, based on User as SysId 3 Enter #SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM ORDR as SQL Statement 4 Click Save Button 5 Click Close Button 1 Note: All the sales orders are retrieved in one shot. VariablesTableName and DocStatus will be introduced later, to support dynamically retrieving the document list by document type ,status, and its owner 2 3 4 5

23 Scenario Step Design: xxx.GetDocList: Processing(4/4)Path: Scenarios/Step Design/Working Step/[Processing] After the configuration the Processing diagram should be showing a green light icon at the left and top of sqlCall atoms. The next step is to modify the XSLT file of the Final atom using your preferred XML Editor. In order to have access to the XSLT file, WebDAV should be enabled as “full”. Refer to B1if Installation slides for instruction.

24 XMLSpy project Open the project with XMLSpyWe’ll implement the final transformation of sql call result in atom0.xsl

25 Edit atom0. xsl (Final) of xxxEdit atom0.xsl (Final) of xxx.GetDocList to transform the sql call result into the target format Add “b1settings” variable as the last variable in the atom.xsl file, this variable will load the b1settings.xml file, holding the decimal settings of B1 (the settings are stored into B1if at1st mobile connection to SAP Business One). The settings will be used to format the DocTotal field as format “666,66 $” – number and currency. Add a reference to b1.xsl and string.xsl libraries at the end of atom0.xsl (just before end tag )

26 Edit atom0.xsl (Final) to transform the sql call result into the target format Transform the sql call result of atom1 into the target format. It depends on the atom id of sql Call Format the DocTotal as “number + currency” format

27 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

28 Create and upload a xml file for test inbound message with root tag 1 Create an XML file with content below for test inbound message: 2 Save the file as ‘test_in_msg.xml” 3 Open B1iP Control Center from path: Integration Framework for SAP Business One => Control Center 4 Upload to BizStore with Control Center from path: Maintenance/BizStore Upload Select the test_in_msg.xml saved above. Choose BizStore-URI as /com.sap.b1i.vplatform.scenarios.design/vBIU.xxx.GetDocList/test_in_msg.xml(unified) Click Submit button

29 Debugging and Test 1 2 Path: Scenarios/Step Design/ 1 2Choose xxx.GetDocList as Scenario Step Identifier 2 Click Processing Button 1 2

30 Debugging and Test Path: Scenarios/Step Design/Working Step/[Processing] 1 Click Test Button 2 Choose 001sap0003 WSforMobile as Test Sender System 3 Choose as Test user based B1 4 Choose test_in_msg.xml as Inbound-Message 5 Click Save Button 6 Click Run Button 7 Click Debug Button 8 Click Result Button 1 2 3 4 5 6 7 8

31 Step 1: Inbound

32 Step 2: Processing – Atom1 (sqlCall) Retrieving the doc list with JDBC call

33 Step 3: Processing – Atom0 (Final Transformaiton) Transforming the sql call result in to final outbound format

34 Step 4: Outbound Result

35 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

36 Add Inbound Variables TableName and DocStatus in sqlCallPath: Scenarios/Step Design 1 Choose xxx.GetDocList as Scenario Step Identifier 2 Click Processing Button 1 2 Note: B1if support both global and local variables, retrieving the parameter from inbound message. Making the scenario more flexible and reusable. We are going to create 3 local variables for Atom 1(sqlCall) TableName: the table name of document, e.g. ORDR - sales order, OINV - A/R Invoice etc -DocStatus: the status of document, e.g. O – Open, C – Closed, “”(empty) - All

37 Add Local Variables for sqlCall: Variable#1 - TableNamePath: Scenarios/Step Design/Working Step/[Processing] 1 Click the pen icon to edit the sqlCall atom 2 Click “Lcl. Vars” button in edit SQL CALL window 3 Click Add button to add a new variable 4 Enter TableName as variable name 5 Click Select button 6 Enter $msg/*/b1mb:TableName as Xpath for variable TableName 7 Click Save button 1 3 4 2 5 6 7 Inbound Parameter - Table Name of Document Retrieving from inbound request message Xpath: $msg/*/b1mb:TableName

38 Add Local Variables for sqlCall: Variable#2 - DocStatus1 Click Add Button to add a new variable 2 Enter DocStatus as variable name 3 Click Select button 4 Enter $msg/*/b1mb:DocStatus as Xpath for variable DocStatus 5 Click Save button 6 Click Close button 7 7 1 3 2 4 Inbound Parameter - DocStatus (Document Status) Retrieving from inbound request message XPath: $msg/*/b1mb:DocStatus 6 5

39 Using variables in sqlCall: Replacing the hardcode ORDR and Open statusPath: Scenarios/Step Design/Working Step/[Processing] 1 Enter #SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM $string(TableName) WHERE DocStatus = '$string(DocStatus)' OR '$string(DocStatus)' = '' as SQL Statement 2 Click Save button 3 Click Close button 1 2 3 SQL Statement with variable: #SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM $string(TableName) WHERE DocStatus = '$string(DocStatus)' OR '$string(DocStatus)' = '' Note: it should be ‘$string(DocStatus)’ with single quotes, not $string(DocStatus) If $string(DocStatus) is empty, all Sales Orders will be retrieved. Important Note: Replace all ‘ signs in the SQL query after copying it from here, the signs are different.

40 Modify the test inbound request message: Add TableName and DocStatusTarget file: You can edit the test inbound message uploaded in slide 29 with your preferred XML editor supporting WebDAV. To Do: -Add TableName as ORDR (Sales Order) -Add DocStatus as O (Open) -Save the test_in_msg.xml Content of test_in_msg.xml: ORDR O

41 Debug and Test: Get all the open sales orders Inbound => Run => Debug => ResultPath: Scenarios/Step Design/Working Step/[Processing] 1 2 3 4 5 All the open sales orders

42 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

43 Access Control: Filter the document by current logon user as sales employee1 2 Business Requirement: Access control to sales marketing document s by owner. Mostly, the sale employees are only allowed to view their own documents. Solution: Filter the document list by sales employee binding to SAP Business One user in Employee master Data

44 Using variables in sqlCall: Filter the document by current logon user as sales employeePath: Scenarios/Step Design/Working Step/[Processing] 1 Click pen icon to edit sqlCall atom 2 Enter SQL Statement in the note below 3 Click Save Button 4 Click Close Button 1 2 3 4 SQL Statement with variable: #SELECT DocEntry, CardCode, CardName, DocDate, DocTotal FROM $string(TableName) T0 INNER JOIN OHEM T1 ON T0.SlpCode = T1.salesPrSon INNER JOIN OUSR T2 ON T1.userId = T2.USERID WHERE (DocStatus = '$string(DocStatus)‘ OR '$string(DocStatus)' = '') AND T2.USER_CODE = '$string(Login)' Note: 1.It should be ‘$string(DocStatus)’ with semi-quote comma, not $string(DocStatus) 2.$string(Login) is a default variable defined in sap.B1Mobile as the current login use. XPath: $msg/*/b1mb:userName

45 Modify the test inbound request message: Add userName as the login user in MobileTarget file: The test inbound message uploaded in page 29, you can edit it with your preferred XML editor supporting WebDAV To Do: -Add userName for the login user -Save the test_in_msg.xml Content of test_in_msg.xml: ORDR O manager

46 Debug and Test – All open sales order for manager Inbound=>Run=>Debug=>ResultPath: Scenarios/Step Design/Working Step/[Processing] 1 2 3 4 5 All the open sales orders for manager

47 Activate the scenario for run-timePath: Scenarios/Control 1 Check the check box of xxx.B1Mobile to activate it 2 Click Activate button 1 2

48 Agenda Overview Case Analysis Integration Test SetupWeb Services in B1if Mobile Solution Architecture Procedure to extend Case Analysis Get document list by doc type, status and sales employee Integration Scenario Package Scenario Step Inbound Outbound Processing Test Get all sales order Get all open sales order Get all open sales order by sales employee Setup Export package from dev system Deactivate the package in customer system Import and Activate package in customer system

49 Export the Package from development systemPath: Scenarios/Export 1 Choose xxx.B1Mobile as Scenario Package Identifier 2 Check the check box to Add test messages 3 Click the button Package Export 1 2 3 Note: Export the package and save it as Zip file from Development System

50 Deactivate sap.B1Mobile in Customer SystemPath: Scenarios/Control 1 Uncheck xxx.B1Mobile package to deactivate 1 Note: Scenario Package can’t be modified in active mode, only can be modified in design mode.

51 Import the updated package into customer systemPath: Scenarios/Import 1 Browse the xxx.B1Mobile.zip package copied from dev system 2 Click Submit button 1 2

52 Activate the package in customer system for run-timePath: Scenarios/Control 1 Check the check box of xxx.B1Mobile to activate it 2 Click Activate button 1 2

53 XSD and WSDL generationPath: Scenarios/Setup 1 Choose the target Scenario Package Identifier as “xxx.B1Mobile” 2 Click Tools button 3 Choose Document as “XSD Generation” 4 Click Select Button 5 Choose Document as “WSDL Generation” 6 1 2 3 4 5 6

54 Test using with wfetch toolNote: User and Password for B1 application can be seen because we didn’t set “Enforce Secure Transport”. sap.B1Mobile scenario is configured by default having SSL authentication as mandatory.

55 Thank You! For more information visit SDN at

56