Salesforce and S/4HANA Cloud Order Aggregation

(0 reviews)

home

I want to aggregate orders from Salesforce and SAP S/4HANA and compare them to see which can only be found in one of the two and which orders are in both systems.

This template generates the result as a CSV report that is sent by email to addresses you can configure.

This template gets orders from Salesforce and SAP S/4HANA, matches by the SAP4HANA_Order_Key__c in Salesforce and SalesOrder in SAP S/4HANA, and generates a CSV file which shows orders in Salesforce, orders in SAP S/4HANA and orders in both systems. The report is then emailed to a configured group of email addresses.

License Agreement

This template is subject to the conditions of the MuleSoft License Agreement. Review the terms of the license before downloading and using this template. You can use this template for free with the Mule Enterprise Edition, CloudHub, or as a trial in Anypoint Studio.

Considerations

To make this template run, there are certain preconditions that must be considered. All of them deal with the preparations in both source (Salesforce) and destination (SAP S/4HANA) systems, that must be made for the template to run smoothly. Failing to do so can lead to unexpected behavior of the template.

Before you continue with the use of this template, you may want to check out this Documentation Page, that teaches you how to work with SAP S/4HANA and Anypoint Studio.

Salesforce Considerations

Here's what you need to know about Salesforce to get this template to work:

As a Data Source

If the user who configured the template for the source system does not have at least read only permissions for the fields that are fetched, then an InvalidFieldFault API fault displays.

java.lang.RuntimeException: [InvalidFieldFault [ApiQueryFault
[ApiFault  exceptionCode='INVALID_FIELD'
exceptionMessage='Account.Phone, Account.Rating, Account.RecordTypeId,
Account.ShippingCity
^
ERROR at Row:1:Column:486
No such column 'RecordTypeId' on entity 'Account'. If you are attempting to
use a custom field, be sure to append the '__c' after the custom field name.
Reference your WSDL or the describe call for the appropriate names.'
]
row='1'
column='486'
]
]

This template makes use of the External ID field offered by Salesforce. Here is a short description on how Salesforce define external ID's.

The template uses the External ID in order to do xRef between the entities in both systems. The idea is, once an entity is created in Salesforce it's decorated with an ID from the source system which will be used afterwards for the template to reference it.

You will need to create a new custom field in your Order entity in Salesforce with the following name: SAP4HANA_Order_Key__c

For instructions on how to create a custom field in Salesforce, please, check this link.

SAP S/4HANA Considerations

Here's what you need to know to get this template to work with SAP S/4HANA.

As a Data Destination

There are no considerations with using SAP S/4HANA as a data destination.

Run it!

Simple steps to get this template running.

Running On Premises

In this section we help you run this template on your computer.

Where to Download Anypoint Studio and the Mule Runtime

If you are new to Mule, download this software:

Note: Anypoint Studio requires JDK 8.

Importing a Template into Studio

In Studio, click the Exchange X icon in the upper left of the taskbar, log in with your Anypoint Platform credentials, search for the template, and click Open.

Running on Studio

After you import your template into Anypoint Studio, follow these steps to run it:

  • Locate the properties file mule.dev.properties, in src/main/resources.
  • Complete all the properties required as per the examples in the "Properties to Configure" section.
  • Right click the template project folder.
  • Hover your mouse over Run as.
  • Click Mule Application (configure).
  • Inside the dialog, select Environment and set the variable mule.env to the value dev.
  • Click Run.After you import your template into Anypoint Studio, follow these steps to run it:
  • Locate the properties file mule.dev.properties, in src/main/resources.
  • Complete all the properties required as per the examples in the "Properties to Configure" section.
  • Right click the template project folder.
  • Hover your mouse over Run as.
  • Click Mule Application (configure).
  • Inside the dialog, select Environment and set the variable mule.env to the value dev.
  • Click Run.To make this template run on Studio there are a few extra steps that needs to be made.Check this Documentation Page: Enabling Your Studio Project for SAP S/4HANA.

Running on Mule Standalone

Update the properties in one of the property files, for example in mule.prod.properties, and run your app with a corresponding environment variable. In this example, use mule.env=prod.

Running on CloudHub

When creating your application in CloudHub, go to Runtime Manager > Manage Application > Properties to set the environment variables listed in "Properties to Configure" as well as the mule.env value.

Deploying a Template in CloudHub

In Studio, right click your project name in Package Explorer and select Anypoint Platform > Deploy on CloudHub.

Properties to Configure

To use this template, configure properties such as credentials, configurations, etc.) in the properties file or in CloudHub from Runtime Manager > Manage Application > Properties. The sections that follow list example values.

Application Configuration

HTTP Connector Configuration

  • http.port 9090

Salesforce Connector Configuration

  • sfdc.username bob.dylan@sfdc
  • sfdc.password DylanPassword123
  • sfdc.securityToken avsfwCUl7apQs56Xq2AKi3X

SAP4HANA Connector Configuration

  • s4hana.baseUrl your.sap4hana.address.com
  • s4hana.username your.sap4hana.username
  • s4hana.password your.sap4hana.password

SMTP Services Configuration

  • smtp.host smtp.example.com
  • smtp.port 587
  • smtp.user exampleuser@example.com
  • smtp.password ExamplePassword456

Email Details

  • mail.from exampleuser@example.com
  • mail.to woody.guthrie@example.com
  • mail.subject Salesforce and SAP S/4HANA Orders Aggregation Report
  • mail.body Report comparing orders from Salesforce and SAP S/4HANA
  • attachment.name Report.csv

API Calls

Salesforce imposes limits on the number of API calls that can be made. However, this template

only makes one API call to Salesforce during aggregation.

Customize It!

This brief guide provides a high level understanding of how this template is built and how you can change it according to your needs. As Mule applications are based on XML files, this page describes the XML files used with this template. More files are available such as test classes and Mule application files, but to keep it simple, we focus on these XML files:

  • config.xml
  • businessLogic.xml
  • endpoints.xml
  • errorHandling.xml

config.xml

This file provides the configuration for connectors and configuration properties. Only change this file to make core changes to the connector processing logic. Otherwise, all parameters that can be modified should instead be in a properties file, which is the recommended place to make changes.

businessLogic.xml

The functional aspect of the template is implemented in this XML, directed by one flow responsible for conducting the aggregation of data, comparing records, and finally formatting the output as a CSV report.

Using the Scatter-Gather component, this template queries the data in different systems. After that the aggregation is implemented in a DataWeave 2 script using the Transform component.

Aggregated results are sorted by:

  1. Orders in Salesforce only.
  2. Orders in SAP S4HANA only.
  3. Orders in both Salesforce and SAP S4HANA.

The result is transformed to CSV format. The final report in CSV format is sent to the email addresses you configured in the mule.*.properties file.

endpoints.xml

This is the file where you find the endpoint to start the aggregation. This template uses an HTTP Listener to trigger the use case.

Trigger Flow

HTTP Listener - Start Report Generation

  • ${http.port} is set as a property to be defined either on a property file or in CloudHub environment variables.

  • The path configured by default is generatereport and you are free to change as you prefer.

  • The host name for all endpoints in your CloudHub configuration is localhost. CloudHub then routes requests from your application domain URL to the endpoint.

errorHandling.xml

This file handles how your integration reacts depending on the different exceptions. This file provides error handling that is referenced by the main flow in the business logic.


Reviews

TypeTemplate
OrganizationMulesoft Inc.
Published by
MuleSoft Organization
Published onNov 26, 2019
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.0

Categories

Pattern
AggregationNo values left to add
Products
SalesforceSAPNo values left to add

Tags