Contents


Overview

Skill Level: Intermediate

Prior completion of DWRecipe necessary for Context

This is the parsing side of our previous recipe where we query cloud database and return raw data in a form of JSON. Here we will show the steps for parsing this object via JSON and a toolkit inside IBM BPM.

Ingredients

  • BPM JSON Helper Toolkit
  • To have completed the past article Past Article
  • Your Node Server running on Bluemix
  • Your Database running on Bluemix
  • BPM

Step-by-step

  1. Preparing BPM

    1. Download the BPM JSON Helper Toolkit
      1. IBM JSON Parser Community Toolkit
    2. To install go to Process Center in the top right of your screen
    3. Click Toolkits
    4. Then Click Import toolkit
      1. twx file V3.1_8.5.0 included in the JSON Parser toolkit
    5. Go to the Process Designer in your process
    6. Add the toolkit in left column
    7. It may show a red error, you can ignore this as it will still function and is throwing an error due to version mismatch
    8. Screen-Shot-2016-12-15-at-8.11.57-PM
  2. How to Format JSON Parsing to TW and BPM

    1. Click all in the BPM JSON Helper toolkit
    2. Click Convert JSON to TWObject Sample
    3. Click JSON Convert to TW in the Human Service
    4. Parsing is called by this one line of text
      1. tw.local.sampleType = BPMJSON.convertJSONToTw(tw.local.jsonText);
    5. The tw.local.sampleType is an object that holds the configuration of what you're parsing
    6. the tw.local.jsonText is the JSON string to parse
  3. Setting up your Implementation of the Parser

    1. Go to your data tab in the Process Designer
    2. Create a new data object
    3. You must have your object set up in the format “ObjectName” which is whatever you want to call the data object, in this case we’ll call it EmailAddress. It does not need to correlate to anything, and is used for your reference.
      1. This complex object must have fields to map exactly to the JSON column name which matches to the SQL Column Name. In this case we can see the column name is emailaddress. So our EmailAddress object has a string called emailaddress.Screen-Shot-2016-12-15-at-5.37.17-PM
    4. Go to your Systems Service where you are implementing the HTTP request to pull from the database. In my case this is called “Pull from DB”
    5. Create an output variable called emailAddress that is a list of the data objects we created.
      1. To summarize we are creating emailAddress, a list of objects of type EmailAddress that have one field called emailaddress of type string.
      2. Screen-Shot-2016-12-15-at-8.20.37-PM
  4. Setting Up and Writing the Javascript

    1. First we must drop a piece of Client Side Script after we interact with the HTTP request to get our database information
    2. Place this code right after the Read from HTTP Integration Service
    3.  In this we must first initialize our object.
      1. tw.local.emailAddress = new tw.object.listOf.EmailAddress
    4. After we have initialized our object we must convert the object through our JSON to TW Toolkit code. This code we found is the one line parser in Step 2.
    5. After the initialization add this code
      1. tw.local.emailAddress = BPMJSON.convertJSONToTW(tw.local.resultDB)
    6. This resultDB is the htmlResult returned from the “Read From HTTP” Integration service inside our systems service.
    7. Screen-Shot-2016-12-15-at-8.29.07-PM
  5. Viewing the Results Client Side in BPM

    1. Go to your Client Side Human Service

    2.  

      Add a private variable of type EmailAddress called emailAddress. Ensure this is a list

    3. Screen-Shot-2016-12-15-at-8.30.43-PM
    4. Click on your coach so you can see the UI to place.

    5. On the right side, drag your variable emailAddress on the screen.

    6. Screen-Shot-2016-12-15-at-8.32.21-PM
    7. Ensure that your data mapping on the Human service for the systems service is mapped from emailAddress of the Systems Service to emailAddress of the Client Side Service

    8. Launch your client side human service and see the result!
    9. Screen-Shot-2016-12-15-at-8.33.59-PM
  6. Conclusion

    If you have any questions feel free to reach out to me. My email address is zachary.silverstein@ibm.com

     

    Special thanks to Kris Stowers for teaching me about JSON parsing inside BPM

4 comments on"Parsing returned data from a NodeJS Server inside BPM Via HTTP"

  1. It seems this solution does not work in IBM BPM 8.5.7 Update 2017/03 and 2017/06 – I always get this error: listLength not defined
    I could however completely replace BPMJSON.convertJSONToTW() with JSON.stringify().

    Did anybody else have issues with Update 2017/06 like this?

Join The Discussion