ERP Integration

One of the most common integrations with Propel is an integration with an Enterprise Resource Planning (ERP) System. Common ERP Systems customers integrate with include SAP, Microsoft Dynamics, Netsuite, and Oracle Cloud. While each system handles product data uniquely, there are some generic patterns that can be used to retrieve all necessary data out of Propel. This article's purpose is to provide a middleware agnostic approach to fetching product data from Propel used to populate your ERP system.

ERP Integration Partners

If you are in need of an ERP Integration and do not have in-house development resources, please contact your Account Manager to learn more about our recommended ERP Integration partners.

Realtime Integrations (Recommended)

By far, the most common use case is what we call the "Product Master". This use case entails transfering Product data from Propel to your downstream ERP System in order to facilitate additional business processes along the value chain.

Data is transferred on a per Change Order basis, preferrably in realtime. The data needed to populate ERP includes Affected Items (including Item and Item Revision data), Bill of Materials (BOMs), and Approved Manufacturers Lists (AMLs). Please see the Core Objects ERDs for more information about how these objects are related from a data model perspective.

Architecture

This architecture assumes a realtime integration which is a recommended best practice.

The sequence of events can be defined at a high-level as such:

  1. The data exchange begins with an event, the release of a Change Order in Propel.
  2. When a Change Order is released, either a Platform Event or Outbound Message is triggered and received by your Middleware of choice. Either messaging technology can be used based on your Middleware's compatibility.
  3. Your Middleware can then use our REST API to fetch the Release Package for the Change Order.
  4. Your Middleware performs transformations and translations and inserts the data into your ERP System.

Express App as Middleware Example

In this example, we'll setup an Express app to act as the Middleware and receive notifications when Change Orders are released and then fetch their Release Packages. You can access the full sample code here.

We'll be doing the following in this example:

  1. Create a Connected App if Using OAuth (Optional)
  2. Create an Express App
  3. Authenticate with Propel
  4. Receive Platform Event Messages
  5. Fetch the Release Package for a Change Order

1. Create a Connected App if Using OAuth (Optional)

tip

Only follow this step if you plan to use OAuth instead of basic authentication. This example uses basic username/password authentication.

First, you'll need to open a connection with Salesforce in order to make API calls. You will get a client and secret key after creating a connected app.

  1. In Salesforce Lightning, Go to Salesforce Setup > App Manager
  2. Click New Connected App on the App Manager page
  3. Name: ERP Integration, API Name: Propel_ERP_Integration, Contact Email: your_email
  4. Enable OAuth Settings
  5. Callback URL: http://localhost:4000/oauth2/callback
  6. Selected OAuth Scopes: (full), (api), (web), (refresh_token, offline_access) It is recommended to have at least these four scopes selected.
  7. Save

Make sure to save your client and secret key for connecting your application. You'll need it in the next steps.

2. Create an Express App

Create a new folder and create a package.json file with the following to ensure you have installed the right dependencies:

package.json
{
"name": "erp-middleware-sample",
"version": "1.0.0",
"description": "Example showing how to receive a platform event message and make a callout to the release package endpoint.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1",
"jsforce": "^1.9.3"
}
}

In this example, we'll be using two libraries, JSForce and Express. JSForce will allow us to easily authenticate and make API calls to Propel and Express will be our server that will handle routing.

Once you've copied package.json, run npm install in your command line to install the required libraries.

Now that you have your dependencies installed, create index.js. Add the following code to your file:

index.js
const express = require('express');
var jsforce = require('jsforce');
const config = require('./config.js');
const app = express()
const port = 4000
const namespace = config.namespace || 'PDLM'
app.get('/', function(req, res) {
res.send('Hello World')
});
app.listen(port, () => console.log(`Example app listening at http://localhost:${port}`))

You can now type node index.js into command line to run the server.

3. Authenticate with Propel

Next, we'll authenticate with Propel using a basic authentication scheme. Open config.editme.js from the code sample repository and fill in your Username, Password (may require security token as well), and Namespace (use PDLM).

Once you've entered your credentials, rename the file to config.js.

In index.js add the following code after const namespace = config.namespace || 'PDLM' to use your credentials to authenticate via Salesforce:

index.js
conn.login(config.username, config.password, function(err, userInfo) {
if (err) { return console.error(err); }
console.log("Authenticated and waiting for a message...");
});

Run the command node index.js to see if your authentication was successful. If it was you'll see the following message in the console:

Example app listening at http://localhost:4000
Authenticated and waiting for a message...

4. Receive Platform Event Messages

After successfully authenticating, we're now ready to subscribe to the Platform Event that will let us know when a Change Order is released. For more information on Platform Events, please see this article.

In this example, we'll be subscribing to the PDLM__Change_Event__e that is triggered anytime a change order transitions status.

Add the following code within the method you used to authenticate with Propel. Also, we'll introduce a helper method called withNamespace to add the namespace to fields:

index.js
conn.login(config.username, config.password, function(err, userInfo) {
if (err) { return console.error(err); }
conn.streaming.topic(`/event/${withNamespace('Change_Event__e')}`).subscribe(function(message) {
var response = message.payload;
console.log(response);
});
});
var withNamespace = function(field) {
return namespace + '__' + field;
};

If you run node index.js and create, update, or release a change order in Propel, you should see a response in the console similar to the following:

{
PDLM__Is_Approved__c: true,
CreatedById: '0053j00000Ae8xDAAR',
PDLM__Is_Update__c: true,
PDLM__Is_Descriptive__c: false,
CreatedDate: '2020-09-03T00:11:44Z',
PDLM__Record_Id__c: 'a0E3j0000167KzaEAE',
PDLM__Is_Cancelled__c: false,
PDLM__Session__c: '--omitted--',
PDLM__Value__c: null }
}

5. Fetch the Release Package for a Change Order

Finally, once we receive the Platform Event notifying us that a Change Order has been released, we can make a callout to the Release Package Endpoint (Since 6.4) to fetch details about the Change Order and all related records such as Affected Items, BOMs, AMLs, and Attachments.

Add the following code within the authentication method:

index.js
conn.streaming.topic(`/event/${withNamespace('Change_Event__e')}`).subscribe(function(message) {
var response = message.payload;
var requestURLParams = '?affectedItems=true&bom=true&amls=true&attachments=false';
// check to see if change event is triggered by a release
if(response[withNamespace('Is_Approved__c')]) {
conn.apex.get(`/services/apexrest/${config.namespace}/api/v3/change/${response[withNamespace('Record_Id__c')]}${requestURLParams}`)
.then( (resultRows) => {
console.log(resultRows);
})
.catch((e)=>{
console.log(e);
});
}
});

First, we determine which URL Parameters to pass to the endpoint. In this case we've selected to fetch all Affected Items, BOMs, and AMLs associated with this Change Order.

var requestURLParams = '?affectedItems=true&bom=true&amls=true&attachments=false';

Second, we filter Platform Event messages by release events only. The Is_Approved__c flag determines if the triggering event was a release.

if(response[withNamespace('Is_Approved__c')]) {

Third, we make a callout to the Release Package endpoint (/v3/change/:changeId) using the Record_ID__c from the Platform Event.

conn.apex.get(`/services/apexrest/${config.namespace}/api/v3/change/${response[withNamespace('Record_Id__c')]}${requestURLParams}`)

To test this code, run node index.js and release a Change Order in Propel. Once you receive the payload from the Release Package endpoint, you will need to transform this data to insert it into your ERP system.

Batch Processing Integration

Try a Realtime Integration First

We highly recommend you build a realtime integration first, if possible. Realtime Integrations provide your users with more up-to-date, accurate mission critical data needed to make decisions.

In some cases, it may be required to query Propel periodically for Product data to update your ERP system. Please note, this is not our recommended approach, but may be necessary where realtime integrations are not viable due to various constraints (typically due to Middleware compatibility issues).

You can find more information about setting up this integration path in our Help Desk.