Flow Designer Subflow- How do I get custom variables from JSON Payload?

TramaineM
Kilo Sage

This is going to be a very noob question but I'm working on my coding skills 🙂

I'm using the Jira Spoke to integrate Jira with our ServiceNow instance. I have it working mostly except that it is not getting the values of 5 custom fields that are within the payload. These custom fields were added in Jira to match the existing Change record fields such as Justification, Test Plan etc. in ServiceNow. 

In the payload, they are called customfield_11247 through customfield_11251. Here is an example: 

In the subflow (which was cloned from the Process Jira Webhook subflow), I added the custom fields individually as a new input and the type "string", but they are showing blank when the webhook is triggered. 

I would think it would be string since it's not an object containing additional fields, but any help would be appreciated? Thanks!

1 ACCEPTED SOLUTION

Hey ok so here's another, better approach that doesn't require you to modify any script includes that they locked down. I don't know why I didn't even see this before.

You have inputs.payload in the subflow which is a string of the entire payload so all you gotta do in your Flow Designer is create your own action, with a script step. Now you make payload an input to the step, and the outputs can be all your custom fields. Now you can get to them like

var allInputs = JSON.parse(inputs.payload);
outputs.customfield11247 = allInputs.issue.fields.customfield_11247;

So that's just one example now you can make customfield11247 an output variable to your script step and an output to the action you created. Now you can access all your custom fields this way, just pass the payload to your custom action in the subflow.

And you don't even have to change the inputs to the subflow.

I went down the rabbit hole on this one but now I don't even think it was necessary 🙂

View solution in original post

15 REPLIES 15

Ok so just from that small snippet of code I can see in your screenshot it looks like the customfields are being assigned as part of a JSON. Is the JSON they're being assigned to an output like outputs.jsonObj for example? You probably do need these string variables to be nested in an output object variable is what I'm thinking. But it's hard to know whithout seeing the full picture of the spoke and unfortunately I can't get it installed in PDI

Hey Chris, 

Thanks for taking the time to respond and for your help. 

I tried the other day since these custom fields are under the Fields object. Here is the current way it's setup:

find_real_file.png

I added the Fields object under the Issue object, which is included in the Jira Spoke.

find_real_file.png

Ok got my hands on an instance with the spoke installed.

Did you update the decision table to use the new subflow? Go to the "System Definition" -> "Decision Tables" and open the "Jira Webhook Decision Policy" one then you open the default decision in decisions related list and update the answer field to be the new subflow you created instead of the out of the box one

Yes I did, but I went to the Jira Webhook application/module and did it from the routing policies. 

However, I think you pointed me in the right direction with the Decision Tables. From there, I can try adding the new Decision Inputs for the custom fields and see if that brings it in. 

That's worth a try but I would think that's fine to be left alone, because the decision inputs shouldn't really matter unless you needed to trigger different subflows based on the input values.

However I think I found something else.

Take a look at the script include JiraWebhookUtil it looks like it looks like SNOW hardcoded the inputs in the function buildIssueDetails. And to make matters worse, they locked down the script include to read only protection policy.

That being said you can edit the script include 'JiraWebhookIssueInputBuilder' in the function called "buildSubFlowInputs" look at line 35 where they set inputs['issue'];

So what you should do is try right after line 36 where they set issueFields = issue.fields add this code like

 inputs.issue.fields = issueFields;

Please try making this change to the script include and see if it makes any difference