Flow/subflow array.object value extraction

ericgilmore
Tera Guru

ver. Tokyo

 

Hello, I'm currently wrestling with extracting values from a complex object within a subflow. Using Jira Spoke, and a webhook setup, when a JIRA issue is updated the data from that update is being pushed (integration) to our SN instance. It's a relatively straightforward JSON object value extraction operation. Until I ran into a couple Array.Objects in the data.

 

In the JSON this is what I see:

 

jira:issue_updated{
    "timestamp": 1691044740524,
    "webhookEvent": "theHook",
    "issue_event_type_name": "issue_updated",
    "user": {
        "self": "https://some.url.com",
        "name": "Bob",
        "key": "bob",
        "emailAddress": "bob@some.org",
        "active": true,
        "timeZone": "America/West"
    },
    "issue": {
        "id": "15525",
        "self": "self",
        "key": "123456",
        "fields": {
            "customfield_10630": null,
            "customfield_10510": null,
            "customfield_10631": null,
            "customfield_12800": null,
            "customfield_11700": {
                "self": "https://some.url.com/rest/api/2/customFieldOption/13600",
                "value": "Consolidated",
                "id": "13600",
                "disabled": false
            },
            "fixVersions": [
                {
                    "self": "https://some.url.com/",
                    "id": "22",
                    "description": "RWR",
                    "name": "RWR",
                    "archived": false,
                    "released": false
                }
            ],
~
~
~
        }
    }
}

 

 

The subflow  inputs for the array.object is like so:

subflowInput.png

 

The data pill view:

dataPills.png

 

The update record view:

catchVariable.PNG

 

The functions added to the variable:

transforms.PNG

transforms2.PNG

 

The runtime value:

u_release=[unnamed]

I've tried various methods to pull this value but none have worked thus far. If anyone else has experience with this some insight would be greatly appreciated.

 

1 ACCEPTED SOLUTION

ericgilmore
Tera Guru

Ok, here's what worked for me. I decided to create a Flow Action to process the JSON payload in an attempt to extract that value from the Array.Object in question.

 

// Used as a workaround to the Flow/Array.Object value extraction issue we ran into
// inputs: the JSON payload
// JSON Parser step: use the JSON payload to Generate Target

/** Script step **/
// Input Variables
  //   Name        |  Value
// - fixedversion: step 1 > root > issue > fields > fixVersions (Array.Object)
// - payload: Inputs > payload

// Script
function execute(inputs, outputs) {
  var parsedJSON = JSON.parse(inputs.payload)
  var parsedJSONFix = parsedJSON.issue.fields.fixVersions;
  outputs.fixver = parsedJSONFix[0].name.toString();
})(inputs, outputs);

// Output Variables
// - fixver | fixver | String

// Outputs
// IssueID > 1 - JSON Parser step > root > issue > id
// IssueType > 1 - JSON Parser step > root > issue > fields > name
// Release > 2 - Script step > fixver (Our extracted Array.Object value)
// ccbstatus > 1 - JSON Parser step > root > issue > fields > customfield_10120
// expedite status > 1 - JSON Parser step > root > issue > fields > customfield_12002 > value
// link > 1 - JSON Parser step > root > self
// Minor Version > 1 - JSON Parser step > root > issue > fields > customfield_10104
// Description > 1 - JSON Parser step > root > issue > fields > summary
// Orig Behavior > 1 - JSON Parser step > root > issue > fields > customfield_10161
// New Behavior > 1 - JSON Parser step > root > issue > fields > customfield_10162
// FixVersion > 2 - Script step > fixver (Our extracted Array.Object value) 

 

Parse the JSON object to get a JS object.

Descend into the object to find our Array.Object.

Dot walk to our needed value.

Output that value.

 

And there you go. Your mileage may vary.

View solution in original post

3 REPLIES 3

ericgilmore
Tera Guru

Ok, here's what worked for me. I decided to create a Flow Action to process the JSON payload in an attempt to extract that value from the Array.Object in question.

 

// Used as a workaround to the Flow/Array.Object value extraction issue we ran into
// inputs: the JSON payload
// JSON Parser step: use the JSON payload to Generate Target

/** Script step **/
// Input Variables
  //   Name        |  Value
// - fixedversion: step 1 > root > issue > fields > fixVersions (Array.Object)
// - payload: Inputs > payload

// Script
function execute(inputs, outputs) {
  var parsedJSON = JSON.parse(inputs.payload)
  var parsedJSONFix = parsedJSON.issue.fields.fixVersions;
  outputs.fixver = parsedJSONFix[0].name.toString();
})(inputs, outputs);

// Output Variables
// - fixver | fixver | String

// Outputs
// IssueID > 1 - JSON Parser step > root > issue > id
// IssueType > 1 - JSON Parser step > root > issue > fields > name
// Release > 2 - Script step > fixver (Our extracted Array.Object value)
// ccbstatus > 1 - JSON Parser step > root > issue > fields > customfield_10120
// expedite status > 1 - JSON Parser step > root > issue > fields > customfield_12002 > value
// link > 1 - JSON Parser step > root > self
// Minor Version > 1 - JSON Parser step > root > issue > fields > customfield_10104
// Description > 1 - JSON Parser step > root > issue > fields > summary
// Orig Behavior > 1 - JSON Parser step > root > issue > fields > customfield_10161
// New Behavior > 1 - JSON Parser step > root > issue > fields > customfield_10162
// FixVersion > 2 - Script step > fixver (Our extracted Array.Object value) 

 

Parse the JSON object to get a JS object.

Descend into the object to find our Array.Object.

Dot walk to our needed value.

Output that value.

 

And there you go. Your mileage may vary.

This is a perfect example showing how poor Flow Design is. Imagine implementing a code-less application approach and intentionally leaving out, which should of been the very first thing to consider, was the passing of objects between flows, subflows and actions. Cleary showing that whoever was making technical design decisions behind Flow designer, was not a good developer and has cause nothing but PAIN for actual seasoned developers.

Or was it their intention to force actual proper developers out of the SN platform?

bekfro
Kilo Sage

@ericgilmore 

Hoping you can help me... I am trying to retrieve the fix version from the jira issue into a new field I created on the task.

bekfro_4-1709328819932.png

 

 

I have followed your steps about the Flow Action:

Here's my action:

bekfro_0-1709328603108.png

 

bekfro_1-1709328641075.png

bekfro_2-1709328696671.png

If this is correct above what do I need to do in my webhook to get the fix version into the task

bekfro_3-1709328770104.png