Best Way to modify JSON during workflow

Product/components used and version/fix level are you on:

webMethods Webhook Trigger

Detailed explanation of the problem:

Not really a problem, more a question regarding best practice. I have a webhook coming in with user data. One of my fields is the user’s last name. I would like to modify the json and change the last name to “[Not Provided]” if the user’s last name is blank. What would be the easiest way to do this?

Error messages / full error message screenshot / log fileL

Is your question related to the free trial, or to a production (customer) instance?

free trial

Have you installed all the latest fixes for the products and systems you are using?

yes

1 Like

Hi Daniel

One thing you can try is creating a new transformer within one of your actions/steps and set “Transform Data” to Node.js. In the Javascript code you can then check the value coming in, and then use an if statement to modify it. For example, below is a quick sample that will check if my incoming field $request.body.name is = to space. If it is, then it replaces it with the value I provide in unknownname.
unknownname is a project parameter I created to avoid hardcoding.
You don’t have to use a parameter but if you do, then you can change the label in the parameter instead of editing the transformer.

You can add transformers when configuring the action/step. Click the “Add New” button in the Transform section. Then select Node.js in the “Transform Data” field. You will see a small editor on the right side with some sample code. You can then put your own logic in here. In my example I just reference the json data that is available.
Of course the names and locations will be different for you.
Does this make sense?

Note: this is one way to do it. If I think of others I will let you know.

2 Likes

Hi Wayne,

Thanks! This makes sense. This is what my first thought went to, but I wanted to double check and see if there were any predefined transformation modules available that do this.

Best Regards,
Daniel

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.