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

You're correct about the decision inputs.

I feel like we are so close. I went to the JiraWebhookIssueInputBuilder script include but it is also read-only for me. I tried to elevate to security_admin just in case but it didn't work. 

May have to go to HI.

Sorry I didn't see this was read only protection as well. I can help you get around this. If interested please contact me through email or LinkedIn which are publicly available on my profile. If not I totally understand if you'd rather just call in the HI guys 🙂

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 🙂

Thanks so much!

I used this except instead of scripting, I used the JSON parser step after watching Goran Lundqvist's JSON parser video on Youtube. The only difference is they are using REST step for the source data and I just used the payload input like you said. Worked like a charm!

Ah yes nice that's even better.