Transform data in a workflow

Hi folks,

Curious to hear some suggestions for this usecase:

I have a step that generates a list of products ordered line_items, something like this:

[
  {
    "sku": "foo",
    "price": 1500
  },
  {
    "sku": "bar",
    "price": 2000
  }
]

You can see that the price is in cents. I’d like to convert those values to dollars, so divide by 100, before handing the line_items to my smtp service for populating an email template with a summary of products ordered.

Is there a lightweight way to go about this, eg some of the utility steps, or should I just use a code step?

Hi @binamov , Welcome to the community :waving_hand: ,

You can use a Code step with the following code to format the line_items. You need to pass the line_items array in the data field, as shown in the image.

export const code = async (inputs) => {
  return inputs.data.map(item => ({
    ...item,
    price: item.price / 100,
  }));
};

Yeah, that’s what I ended up doing, thanks for the confirmation :folded_hands:

1 Like

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