Skip to Content
Technical Articles

Creating MultiObject Responses using Open Connectors

Open Connectors allows you to connect to 3rd party application data directly from SAP products, like SAP Cloud Platform Integration Flows. You can bring in your contact data from Salesforce, for example, by calling GET /contacts from your Salesforce Open Connector Instance.

But what if the destination that you are syncing data to, like say S/4 Hana, requires a payload to be in a certain structure, containing information from more than one object, like the contact object and the account object? Creating a multiobject response is easy to do with Open Connectors.

There are various ways of accomplishing multiobject responses. In this blog, I’ll run through the most common scenarios and how to tackle them. They are:

Scenario 1 – Return an array of modified objects that contains two or more objects from the SAME Open Connector Instance (e.g. accounts and contacts from the same Salesforce Open Connector Instance)

Scenario 2 – Return a mulitobject response that contains objects from DIFFERENT Open Connectors, like an object that contains fields from the contacts object in Salesforce and the contacts object in Microsoft Dynamics CRM.

Let’s explore each of these scenarios in detail.

 

Scenario 1 – Return an array of modified objects that contains two or more objects from the SAME Open Connector Instance. 

For this scenario, we are going to use the Salesforce contact object and the account object and create a modifield, multiobject that is a contact object with some account object fields. The response will be an array of modified contact objects.

 

{
    "LastModifiedDate": "2017-12-20T02:26:04.000+0000",
    "Languages__c": "English",
    "AccountId": "0011N00001B39TcQAJ",
    "Email": "rose@edge.com",
    "Salutation": "Ms.",
    "MobilePhone": "(512) 757-9340",
    "Name": "Rose Gonzalez",
    "Department": "Procurement",
    "Level__c": "Primary",
    "CreatedById": "0051N0000053hLRQAY",
    "OwnerId": "0051N0000053hLRQAY",
    "Phone": "(512) 757-6000",
    "PhotoUrl": "/services/images/photo/0031N00001JEmOSQA1",
    "IsDeleted": false,
    "IsEmailBounced": false,
    "FirstName": "Rose",
    "Avangate_Record__c": false,
    "Title": "SVP, Procurement",
    "MailingAddress": {
      "street": "313 Constitution Place\nAustin, TX 78767\nUSA"
    },
    "Birthdate": "1965-12-01",
    "SystemModstamp": "2017-12-20T02:26:04.000+0000",
    "CleanStatus": "Pending",
    "LeadSource": "Trade Show",
    "CreatedDate": "2017-12-20T02:26:04.000+0000",
    "Id": "0031N00001JEmOSQA1",
    "LastName": "Gonzalez",
    "Fax": "(512) 757-9000",
    "LastModifiedById": "0051N0000053hLRQAY",
    "MailingStreet": "313 Constitution Place\nAustin, TX 78767\nUSA"
  }

Code Snippet 1 – Salesforce Contact Object

 

{
    "LastModifiedDate": "2017-12-20T02:26:04.000+0000",
    "Ownership": "Public",
    "Description": "Edge, founded in 1998, is a start-up based in Austin, TX. The company designs and manufactures a device to convert music from one digital format to another. Edge sells its product through retailers and its own website.",
    "BillingCity": "Austin",
    "Rating": "Hot",
    "Website": "http://edgecomm.com",
    "LastReferencedDate": "2019-04-02T16:39:18.000+0000",
    "SLA__c": "Silver",
    "NumberOfEmployees": 1000,
    "Name": "Edge Communications",
    "Industry": "Electronics",
    "BillingAddress": {
      "city": "Austin",
      "street": "312 Constitution Place\nAustin, TX 78767\nUSA",
      "state": "TX"
    },
    "CreatedById": "0051N0000053hLRQAY",
    "OwnerId": "0051N0000053hLRQAY",
    "SLASerialNumber__c": "2657",
    "TickerSymbol": "EDGE",
    "Phone": "(512) 757-6000",
    "NumberofLocations__c": 2,
    "UpsellOpportunity__c": "Maybe",
    "PhotoUrl": "/services/images/photo/0011N00001B39TcQAJ",
    "IsDeleted": false,
    "LastViewedDate": "2019-04-02T16:39:18.000+0000",
    "Avangate_Record__c": false,
    "Sic": "6576",
    "ShippingStreet": "312 Constitution Place\nAustin, TX 78767\nUSA",
    "AccountNumber": "CD451796",
    "SystemModstamp": "2017-12-20T02:26:04.000+0000",
    "Type": "Customer - Direct",
    "CleanStatus": "Pending",
    "SLAExpirationDate__c": "2018-01-13",
    "BillingStreet": "312 Constitution Place\nAustin, TX 78767\nUSA",
    "ShippingAddress": {
      "street": "312 Constitution Place\nAustin, TX 78767\nUSA"
    },
    "CreatedDate": "2017-12-20T02:26:04.000+0000",
    "CustomerPriority__c": "Medium",
    "Id": "0011N00001B39TcQAJ",
    "Fax": "(512) 757-9000",
    "LastModifiedById": "0051N0000053hLRQAY",
    "BillingState": "TX",
    "AnnualRevenue": 139000000,
    "Active__c": "Yes"
  }

Code Snippet 2 – Salesforce Account Object

 

The resulting array of objects will be a combination of both of these objects. I’ll call it /combine. It will look like this:

{
    "accountId": "0011N00001B39TcQAJ",
    "contactEmail": "rose@edge.com",
    "contactId": "0031N00001JEmOSQA1",
    "accountName": "Edge Communications",
    "contactLastName": "Gonzalez",
    "accountRating": "Hot"
  }

Code Snippet 3 – An Salesforce contact object that contains two fields from a Salesforce account object – rating and name.

 

The first thing you’ll notice is the multiobject is much smaller. We are going to be building a Common Resource that allows you to define the multiobject’s structure and also name the fields any name.

Let’s see what that looks like:

Img 1 – Creating a Common Resource in the Open Connectors platform.

 

This Common Resource is named /combine and it is mapped to the Salesforce Contact object. The two fields that I want to populate with the Account object are blank for now. The AccountId that lives on the Contact object will be used to grab that Account object and then populate the two unmapped fields. To do this, we need to make a node request in the JS editor ([<>] in the top right) for the Common Resource:

Img 2 – The JS Editor for the Common Resource in Open Connectors

 

This code uses a node request to grab the corresponding Account object and then appending two fields from that object to the contact object.

if(fromVendor){
let accountId = transformedObject.accountId;
const https = require('https');
let options = {
      host: "api.openconnectors.ext.hanatrial.ondemand.com",
      path: "/elements/api-v2/accounts/"+accountId,
      port: 443,
      method: "GET",
      headers: {
          "content-type": "application/json",
          "authorization": `User ${configuration.userSecret}, Organization ${configuration.organizationSecret}, Element ${configuration.elementInstanceToken}`
        }
      };
    
const request = https.request(options, function(res){
      let data = "";
      res.on('data', function(d) {
      data += d;
      }).on('end', function(d) {
         if(res.statusCode === 200) {
           let parsedData = JSON.parse(data);
           transformedObject.accountRating = parsedData.Rating;
           transformedObject.accountName = parsedData.Name;
           done(transformedObject);
         }
         else {
           transformedObject.error = "error";
           done(transformedObject);
         }
    });
});

  request.on('error', function(e){
    transformedObject.error = "error";
    done(transformedObject);
  });
  request.end();
}

Code Snippet 4 – The code placed in the JS Editor of the Common Resource in Open Connecters to create a modified multiobject response composed of the Contact and Account object in Salesforce

 

After saving this, if I now click on the cog button to the left of the Delete button (upper right), I can select Add to API Docs and Removed Unmapped Fields:

Img 3 – Selecting Add to API Docs and Remove Unmapped Fields for this Common Resource in Open Connectors

 

Now I can run this resource like a real resource:

Img 4 – The new /combine Common Resource

 

Running this, I get an array of modified, multiobjects:

[
  {
    "accountId": "0011N00001B39TcQAJ",
    "contactEmail": "rose@edge.com",
    "contactId": "0031N00001JEmOSQA1",
    "accountName": "Edge Communications",
    "contactLastName": "Gonzalez",
    "accountRating": "Hot"
  },
  {
    "accountId": "0011N00001B39TcQAJ",
    "contactEmail": "sean@edge.com",
    "contactId": "0031N00001JEmOTQA1",
    "accountName": "Edge Communications",
    "contactLastName": "Forbes",
    "accountRating": "Hot"
  },
  {
    "accountId": "0011N00001B39TdQAJ",
    "contactEmail": "jrogers@burlington.com",
    "contactId": "0031N00001JEmOUQA1",
    "accountName": "Burlington Textiles Corp of America",
    "contactLastName": "Rogers",
    "accountRating": "Warm"
  },
  {
    "accountId": "0011N00001B39TgQAJ",
    "contactEmail": "barr_tim@grandhotels.com",
    "contactId": "0031N00001JEmOXQA1",
    "accountName": "Grand Hotels & Resorts Ltd",
    "contactLastName": "Barr",
    "accountRating": "Warm"
  },
  {
    "accountId": "0011N00001B39TgQAJ",
    "contactEmail": "bond_john@grandhotels.com",
    "contactId": "0031N00001JEmOYQA1",
    "accountName": "Grand Hotels & Resorts Ltd",
    "contactLastName": "Bond",
    "accountRating": "Warm"
  },
  {
    "accountId": "0011N00001B39ThQAJ",
    "contactEmail": "spavlova@uog.com",
    "contactId": "0031N00001JEmOZQA1",
    "accountName": "United Oil & Gas Corp.",
    "contactLastName": "Pavlova",
    "accountRating": "Hot"
  },
  {
    "accountId": "0011N00001B39ThQAJ",
    "contactEmail": "lboyle@uog.com",
    "contactId": "0031N00001JEmOaQAL",
    "accountName": "United Oil & Gas Corp.",
    "contactLastName": "Boyle",
    "accountRating": "Hot"
  },
  {
    "accountId": "0011N00001B39TiQAJ",
    "contactEmail": "b.levy@expressl&t.net",
    "contactId": "0031N00001JEmObQAL",
    "accountName": "Express Logistics and Transport",
    "contactLastName": "Levy",
    "accountRating": "Cold"
  },

Code Snippet 5 – After calling the Common Resource GET /combine – we retrieve an array with modifield objects that consist of a Contact and Account Salesforce object in Open Connectors.

 

Once we have this Common Resource created, we can run a bulk job on it as we normallly would:

Img 5 – Executing a bulk job using the Common Resource name for the multiobject response in Open Connectors

 

Scenario 2 – Return a mulitobject response that contains objects from DIFFERENT Open Connectors, like an object that contains fields from the contacts object in Salesforce and the contacts object in Microsoft Dynamics CRM.

When working with two or more Connector Instances (like Salesforce and Microsoft Dynamics CRM), one can use a Formula as a Resource (or FaaR) to output the response. Let’s explore this scenario.

First, let’s build a new Common Resource. We’ll name it /combinedContact and we’ll map it to both Microsoft Dynamics OCN Instance and Salesforce OCN Instance.

Img 6 – Mapping a Common Resource to a Salesforce Open Connector Instance – Contact object

 

Next we’ll map it to the Microsoft Dynamics OCN Instance

Img 7 – Mapping a Common Resource to a Microsoft Dynamics Open Connector Instance – Contact object

 

Next, we’ll build a new Formula and name it Combined Contact Data:

Img 8 – The Formulas page in Open Connectors

 

We’ll give it a manual trigger:

Img 9 – Formula triggers in Open Connectors

 

Let’s now build the Formula. First we’ll assume we’ll kick off this Formula by giving it an email {“email”:”some@fake.com”}. The Formula will then call both Salesforce and Dynamics to get the contact we are looking for. Let’s add a where clause query in a script step:

Img 10 – A script step in a Formula that showcases using a normalized query to access any mapped Open Connector Instance

 

Let’s add two Connector Request steps. One to get the contact (using the query) from Salesforce and one to get it from Dynamics. They will both look like this:

Img 11 – A Connector Request step in a Formula

 

The Connector Instance variable can be created here by pressing the plus sign. It can have an arbitrary name. We will set a specific Connector Instance to it after we make a Formula Instance at the end. We will use the Common Resource in the API field. Finally, we’ll put the step that held our query. For the Salesforce Connector Request step, we’ll change the name and add a different Connector Instance variable.

The final step is a script step to create the response we want:

Img 12 –  A script step in Formula Builder in Open Connectors

 

Now let’s edit the Formula (upper right). Let’s change it to v1 (to use FaaR). Do not select revert – just choose it in the dropdown. Give this new “resource” and name and method.

Img 13 – Editing a Formula to turn it into a resource, or a FaaR.

 

Now let’s create a Formula Instance.

Img 14 – Creating a Formula Instance – where the Connector Instances are set.

 

Now let’s grab the Formula Instance Id by clicking on Instances -> Formulas.

 

To run this new FaaR – we have to click on Formulas and hover over the Formula to click on API Docs.

Img 15 – Exposing the API Docs of a FaaR

 

Enter the Formula Instance Id and the trigger body:

Img 16 – Kicking off a FaaR

 

Executing this Formula as a Resource (FaaR) give us:

Img 17 – A combined multiobject response generated from running a FaaR

 

And here we have a response with fields populated from objects from different Connector Instances!

 

In summary, we learned how to return a composite object payload using a Common Resource in Open Connectors. We also learned to return a composite object payload that is made of objects that live on different Connector Instances using a Formula as a Resource, or FaaR.

 

 

 

 

 

 

 

 

 

Be the first to leave a comment
You must be Logged on to comment or reply to a post.