Due to scheduled maintenance, some areas of our site are currently inaccessible. Thank you for your patience.

Please reach out to sales@eonesolutions.com with any questions.

Creating document level run integration tasks in SmartConnect.com

Creating document level run integration tasks in SmartConnect.com

In this post, we will review how to use Global Variables and scripting in SmartConnect.com to create document level after integration tasks. 

In my case, for each record I was processing I needed to update a field in the source system when the record was successfully integrated into the destination. If this was a SmartConnect on premise integration, I would have used a Run Integration task after document success. However, this is not an option in SmartConnect.com. 

I created a global variable to store document numbers of the records that had errors. Then, I used an after integration Run Integration task to update the source records. If the document number of the source record appears in the global variable, then we do not update that document in the source system. 

Step 1: Create a global variable 

  1. On the SmartConnect menu, select Maintenance > Global Variables
  2. Click +Create Global Variable 
  3. Give the global variable a name.
    • In my example, I am calling mine GBL_FAILED_CUSTOMERS because the process I am using it in is creating customer records in the target solution. The actual name you use doesn’t matter, but you will need to adjust the scripts later in the post to use whatever name you use here. 
  4. You do not need to enter a value in the Value field or Secure checkbox. 
  5. Click Save 

Step 2: Catch the documents with errors

Back on the original process, we need to add a task that will update our global variable with the ID of any records that fail. In my case, this is the Customer Number. Because we are using one variable to potentially capture multiple broken records, we need a delimiter between each ID. I have chosen a pipe delimiter (|) as I know that will not appear in my data. You can choose a different delimiter if you like, but just make sure that whatever you use won’t appear in your data naturally. 

Note that I am actually creating 2 tasks here. The first will ensure that the global variable from above is set to an empty string. Technically this step is not required as we saved the variable as an empty string, but I like to do this step just in case. 

  1. Open your integration process. 
  2. Click the Tasks tab. 
  3. Click on +Add Task
  4. Give your task a name. In my example, I called it RESET_FAILED_RECORDS
  5. Select Run Script as the Type. 
  6. Select Integration Pre Tasks as the Stage. 
  7. Enter the following code in the JavaScript Code box: 
//Script to clear variable before processing
this.GBL_FAILED_CUSTOMERS = ''; 
return true;

If you used a different name for your global variable above, you will need to replace “this.GBL_FAILED_CUSTOMERS” with your global variable.

Task Setup
  1. Click Save
  2. Click Add Task
  1. Give your task a name. In the example, I called mine UPDATE_FAILED_RECORDS
  2. Select Run Script as the Type. 
  3. Select Document Post Failure Tasks as the Stage. 
  4. Enter the following script in the JavaScript Code box. 
//Script to concatenate failed customers
this.GBL_FAILED_CUSTOMERS = this.GBL_FAILED_CUSTOMERS + this._companyName + '|' 
return true;

If you used a different name for your global variable above, you will need to replace “this.GBL_FAILED_CUSTOMERS” with your global variable.

  1. Click Save
  2. Click Save on the integration process to save your changes. 

At this point, any time that a record fails, we will record its ID into a pipe delimited list in a global variable.

Step 3: Create a SmartConnect Process to update the source

In my example, I was updating a checkbox on the customer record in my source system to reflect that the integration had succeeded. This meant that I was able to create a process that used the exact same data source as my original integration, and then used the customer entity from that same system as the destination. This is important for the last step of the post. 

In your case, if you need to use a different data source to make your update, you need to ensure that the same ID you used in your first integration is the source grouping for this second integration. 

Step 4: Create a dynamic Restriction

For the process you created in step 3, we need to stop it from processing records that had an error. To do this, we are going to be using the Restrictions feature

  1. Within your process, select the Integration Tab. 
  2. Select the Restriction subtab. 
  3. Enter the following script in the JavaScript Code box: 
//Restrict out records that failed to import
//If the customer is not in the global variable it will not update the record in the target
var customerArray = this.GBL_FAILED_CUSTOMERS.split("|");
if (customerArray.includes(this._companyName)) {
  return false;
} else {
  return true;
}

If you used a different name for your global variable above, you will need to replace “this.GBL_FAILED_CUSTOMERS” with your global variable. 

  1. Click Save on the integration to save your changes. 

Step 5: Call the second process from the first

The last thing we need to do is call the process we just added from the original process. Because we want the update to run whether there is a problem or not, we need to add run integration tasks for both success and failure. 

  1. In the original process, select the Tasks tab. 
  2. Click +Add Task
  3. Give the task a Name.
    • In my example, I used NOTIFY_NS_OF_SUCCESS_S
  4. Select Run Integration as the Type. 
  5. Select Integration Post Success Tasks as the Stage. 
  6. In the Integration to Run field, select the process that you created in Step 3
    • If your second process uses the same data source as the original process, click the Use data from parent checkbox. Do not check this if you used a different data source in your second process. 
  7. Check the Use Parent Variables box. This will ensure that your list of error records is passed to the second process. 
  8. Click Save
  9. Click +Add Task
  10. Repeat the above steps, except: 
  11. Use a different name for this task. I used NOTIFY_NS_OF_SUCCESS_F
  12. Select Integration Post Failure Tasks in the Stage field. 
  13. Click Save
  14. Click Save on the integration to save your changes. 

Summary

In order to use a run integration task at the document level in SmartConnect.com we: 

  • Created a global variable to store the documents we did NOT want to run the second integration for. 
  • Updated the global variable using an after document task. In our case, we needed after document failure. 
  • Created the second integration we wanted to run. 
  • Added a restriction to the second integration that reads the global variable and stops records where the ID exists in the global variable from processing. 
  • Called the second map from the first as both an integration success and integration failure task. 

 

Content
Step 1: Create a global variable  Step 2: Catch the documents with errors Step 3: Create a SmartConnect Process to update the source Step 4: Create a dynamic Restriction Step 5: Call the second process from the first Summary

Feeling stuck? Get the support and guidance you need to help you power through any data challenge

Reset Filters