Ben Langhinrichs

Photograph of Ben Langhinrichs

IBM Champion logo

E-mail address - Ben Langhinrichs







Recent posts

Wed 14 Nov 2018

Short agents



Tue 2 Oct 2018

No cookies for you



Fri 28 Sep 2018

We need more than baby steps


December, 2018
SMTWTFS
      01
02 03 04 05 06 07 08
09 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31

Search the weblog





























Genii Weblog

Driving a RESTful interchange #2 - JSON

Thu 6 Sep 2018, 02:57 PM



by Ben Langhinrichs
Given Tim Davis' recent post, Things to know with JavaScript – JSON, let, const, and arrows, I thought it might be a good time to follow up my recent post on a RESTful interchange between Notes and Salesforce,  and show the JSON I used to push the Notes data to Salesforce. While the raw JSON data (generated using our Midas LSX) is shown below, I'll mention a few of the specifics so you know what you are seeing.
 
1) The Id is the Salesforce ID for the Contact sObject, saved from a previous push of the Salesforce data into Notes to make the roundtrip easier.
 
2) The NotesUNID__c is a custom Salesforce field I added to the ID for the Contact sObject. Salesforce always appends __c to such fields. This is used to make the roundtrip easier from the other direction. This item is created automatically when Midas is told to use JSONFormat='Salesforce'.
 
3)  The AccountID is taken from our document's CompanyName item. It is a native Saleforce field, so doesn't have the __c at the end. Below the JSON, I'll show the export directive which told Midas to call this AccountID. Note that JSON is in UTF8, so this looks Über Øst instead of like Über Øst.
 
4) Phone is a native Salesforce field on the Contact sObject. It is taken from our Tel item.
 
5) Name is a native Salesforce field on the Contact sObject. It is created from a formula language combination of the FirstName and LastName items on our Notes document.
 
6) Email is a native Salesforce field on the Contact sObject. It is taken from the Email item, so doesn't need a mapping.
 
7) SampleBody__c is another custom Salesforce rich text area field I added to the Contact sObject. It is taken from the Notes rich text item, rendered in high fidelity by Midas.
 
{
   "Id": "0030b000023PlWQAA0",
   "NotesUNID__c": "E04775C6408795F4852582F8004945F7",
   "AccountID": "Über Øst",
   "Phone": "+31 025‒6206230",
   "Name": "Gunder van der Wilcox",
   "Email": "GvdWilcox@UberOst.com",
   "SampleBody__c": "<div style=\"line-height:normal;\"><span style=\"font-size: 10pt; font-family: sans-serif; \"><\/span><\/div><div align='left'><table cellspacing='0' cellpadding='0' style='width:430px;border-spacing:0;padding:none;border-collapse:collapse;table-layout:fixed;'><colgroup><col style=\"width:44%;\" \/><col style=\"width:26%;\" \/><col style=\"width:26%;\" \/><\/colgroup><tr style='vertical-align:top;'><td width='191' bgcolor=\"#ffffff\" rowspan='3' style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><img src=\"E04775C6408795F4852582F8004945F7_Notes_0_482.jpg\" alt=\"Inline JPEG image\" height=\"72\" width=\"39\" align='right' style=\"border:none;\" \/><span style=\"font-size: 8pt; font-family: sans-serif; \">Customer<br \/><\/span><span style=\"font-size: 10pt; font-family: sans-serif; \"><strong>Better Budgies Ltd<br \/><\/strong><\/span><span style=\"font-size: 10pt; font-family: sans-serif; \">The Aviary Group<br \/><br \/>Swallowdale 36, South Wutherford<br \/>ESSEX BB01 1BB<br \/>United Kingdom&nbsp;<\/span><\/div><\/td><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><br style=\"clear:both;\"\/><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Date<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">05\/17\/2002<\/span><\/div><\/td><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Quotation Number<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">QN&#8722;99283-MM2<\/span><\/div><\/td><\/tr><tr style='vertical-align:top;'><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Customer Reference<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">BL10923-B573<\/span><\/div><\/td><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Terms of Payment<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">30 days net<\/span><\/div><\/td><\/tr><tr style='vertical-align:top;'><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Valid to<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">06\/17\/2002<\/span><\/div><\/td><td width='114' bgcolor=\"#ffffff\" style=\"padding: 0.0000in 0.0201in; border:1px solid #000000;\"><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">Delivery Time<\/span><\/div><div style=\"margin-left:1%; margin-right:1%; text-indent:1%;\" align='left'><span style=\"font-size: 10pt; font-family: sans-serif; \">2 Wks<\/span><\/div><\/td><\/tr><\/table><\/div><div align='left'><span style=\"font-size: 10pt; font-family: Verdana; \"><\/span><\/div>"
}
 
To generate all this, I used our Export to JSON sample db. This is the Export Directive form, which allows a coding-free definition of what is to be exported.. I am only exporting a single document by UNID, but we can generate by view or selection formula or whatever. Note that with the fields to export, we start with the source item or formula, then an equals sign, then the name to use inside the JSON, so FirstName+" "+LastName=Name uses the formula FirstName+" "+LastName to added the Name in the JSON. This can be any Notes formula, including ones that use @DbLookup, for example.
 
Inline JPEG image
 
So, that is how I generated the JSON to use in the RESTful exchange going from Notes to Salesforce. I'll show the other way around in a future post.

Copyright © 2018 Genii Software Ltd.

What has been said:

No documents found