Tips: For handling content from file servers, such as Amazon S3 or FTP, see the respective connector articles.
In this example, the new Salesforce opportunities have associated PDF contracts, which need to be synced into NetSuite along with the accounts. (Although this example relies on built-in connectors, the same concept is used for a generic HTTP connector.)
First, create the Salesforce export and define the criteria of the records to sync to NetSuite. Choose Export records from source application.
Edit the export and provide a SOQL query, for example:
SELECT id, Name, phone, fax, (SELECT id, name FROM attachments), (SELECT id, title, body FROM notes) FROM Account WHERE name LIKE 'VL_T%'
Observe the Preview data, above. It is important to review and understand the shape of your data retrieved by the query.
{ "attributes": { "type": "Account", "url": "/services/data/v40.0/sobjects/Account/0015A00002LxEoFQAV" }, "Id": "0015A00002LxEoFQAV", "Name": "VL_TEST", "Phone": "(510) 555-5555", "Fax": null, "Attachments": [ { "attributes": { "type": "Attachment", "url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ" }, "Id": "00P5A00001EeqHDUAZ", "Name": "file-amendment.pdf" }, { "attributes": { "type": "Attachment", "url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqH8UAJ" }, "Id": "00P5A00001EeqH8UAJ", "Name": "file-contract.pdf" } ], "Notes": null }
The two file attributes are highlighted within the Attachments array. Keep this JSON structure in mind, because we will process each array object in the next step.
Create a lookup to get each file record in the account, so that we can pass the files in a later import. Choose Look up additional files (per record).
Since Attachments is an array of files (refer to JSON output above), choose Yes for One to many.
Then, provide the path to the JSON child object Path to many that you want to process multiple times. In this example, the child object is Attachments.
Select the SObject type – in this case Attachment, as shown above:
"type": "Attachment",
Finally, provide the JSON Id of the Salesforce record to look for. Whenever a lookup step is executed, it operates on one array object at a time; thus, refer to the id as {{data.Id}}.
"Id": "00P5A00001EeqHDUAZ",
Create response mapping for the lookup and add a new variable, which we’re calling blobKey; use any name you’d like, as long as you are consistent in the rest of the flow’s steps.
Tip
integrator.io assumes that blobKey is the default name for a NetSuite file variable. The advantage to specifying a source record variable name within the response mapping is that the variable is then automatically provided as the default value in the NetSuite file import below.
Give the variable a response field value of data[0].blobKey.
The lookup returns a blobKey field as instructed, and we will pass this variable to the next step in our flow by adding this output into the response mapping.
A lookup always returns an array of objects. For each Attachment object, the blobKey field serves as input for the response mapping step.
[ { "blobKey": "a2949b1546ca420798b77297a48a1950", "Other attributes" : ... } ]
This array of objects is then automatically further wrapped in a data attribute by the response mapping. Hence, we map the value of the new variable to data[0].blobKey.
When this step is completed, the JSON input shown below flows to the next step (importing the files into NetSuite). Note that each attachment now has a blobKey field that holds a reference to the raw file that we fetched from the lookup step.
{ "attributes": { "type": "Account", "url": "/services/data/v40.0/sobjects/Account/0015A00002LxEoFQAV" }, "Id": "0015A00002LxEoFQAV", "Name": "VL_TEST", "Phone": "(510) 555-5555", "Fax": null, "Attachments": [ { "attributes": { "type": "Attachment", "url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ" }, "Id": "00P5A00001EeqHDUAZ", "Name": "file-amendment.pdf", "blobKey" : "a2949b1546ca420798b77297a48a1950" }, { "attributes": { "type": "Attachment", "url": "/services/data/v40.0/sobjects/Attachment/00P5A00001EeqH8UAJ" }, "Id": "00P5A00001EeqH8UAJ", "Name": "file-contract.pdf", "blobKey": "592a17ce5b834d49ba8796f4563c9147" } ], "Notes": null }
For each attachments item found, this step imports the file into the NetSuite file cabinet. Then, it gets the NetSuite fileID so that we can link the IDs with their respective customer accounts (to be created in the next step).
When creating the import, choose Transfer files into destination application.
As in the previous flow step, Attachments is an array of files; here, too, choose Yes for One to many. The Path to the JSON child object in this example is again Attachments.
Then, specify the Folder cabinet ID for your NetSuite account connection.
Under the Add operation, provide the Name of each file to be imported in the Handlebars format {{data.Name}}.
Note
Keep in mind that when this step is executed, it operates on one array object at a time. Thus, we refer to the name as {{data.Name}} without any array notation.
Finally, provide a reference to the raw file in the Blob key path field. This value – blobKey – was defined in the response mapping of the previous step, and it appears as the default value in this import.
Create a response mapping for this import and add a new variable fileid to receive the ID of each file imported into the cabinet and add it to the data available for the next flow step.
When this step is completed, here is the JSON data that flows into the next step:
{ "attributes":{ "type":"Account", "url":"/services/data/v40.0/sobjects/Account/0015A00002LxEoFQAV" }, "Id":"0015A00002LxEoFQAV", "Name":"VL_TEST", "Phone":"(510) 555-5555", "Fax":null, "Attachments":[ { "attributes":{ "type":"Attachment", "url":"/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ" }, "Id":"00P5A00001EeqHDUAZ", "Name":"file-amendment.pdf", "blobKey":"b1126ef16e0c40e8955f96ec9c9b763b", "fileid":"7304" }, { "attributes":{ "type":"Attachment", "url":"/services/data/v40.0/sobjects/Attachment/00P5A00001EeqH8UAJ" }, "Id":"00P5A00001EeqH8UAJ", "Name":"file-contract.pdf", "blobKey":"c499eec2aaca4f9ca26a1114a02ac200", "fileid":"7305" } ], "Notes":null }
Create an import that adds sales records in NetSuite and links them with the respective attachments that we imported into the NetSuite folder.
Select Import records into destination application, since we are not using raw files as input in this step.
Next, define the record type and operation (Add, Update, or Add or update).
In this example, we want to create a corresponding NetSuite account for each Salesforce account. In other words, one exported record translates into one record in the destination. Here, for One to many choose No.
Finally, map an array of attachments to the NetSuite files by passing the file ID, which is stored in the field fileid . Since Attachments is an array, in the import mapping, use Attachments[*].fileid to tell integrator.io to pass the ID to NetSuite.
{ "attributes":{ "type":"Account", "url":"/services/data/v40.0/sobjects/Account/0015A00002LxEoFQAV" }, "Id":"0015A00002LxEoFQAV", "Name":"VL_TEST", "Phone":"(510) 555-5555", "Fax":null, "Attachments":[ { "attributes":{ "type":"Attachment", "url":"/services/data/v40.0/sobjects/Attachment/00P5A00001EeqHDUAZ" }, "Id":"00P5A00001EeqHDUAZ", "Name":"file-amendment.pdf", "blobKey":"b1126ef16e0c40e8955f96ec9c9b763b", "fileid":"7304" }, { "attributes":{ "type":"Attachment", "url":"/services/data/v40.0/sobjects/Attachment/00P5A00001EeqH8UAJ" }, "Id":"00P5A00001EeqH8UAJ", "Name":"file-contract.pdf", "blobKey":"c499eec2aaca4f9ca26a1114a02ac200", "fileid":"7305" } ], "Notes":null }
Comments
I am trying to use the example in this article. However, I am trying to get files attached to an order, i.e. Content documents. For some reason I continue to get the error "resource not found".
I've taken the action item to verify this article and update as needed. Thanks for bringing it to our attention. For now, it's more pressing to get past that error for your integration requirements, and I would recommend entering a support ticket so that we can analyze your flow.
Please sign in to leave a comment.