05-29-2024 04:41 AM - edited 05-29-2024 04:42 AM
In my python snippet I have the following output schema defined, which is a nested list:
Solved! Go to Solution.
05-30-2024 08:37 AM - edited 05-30-2024 08:38 AM
And I don't know Python 😅
I think it's a case sensitivity issue. Your schema screenshot says "TransportOrders", your output screenshot says "transport_orders", and your script screenshot has "Transportorders"
Workato tends to automatically update CamelCase to snake_case (very annoying, but it's only when displaying input/output) , so I think all you need to do is update your code to "TransportOrders" and you'll be set. Hopefully that works.
05-29-2024 07:58 AM
You don't need to map it in, you just need to create the data to match the schema (exactly) and return it.
If my output schema is this:
Then this is how I will return:
def main(input):
## option 1
output = {"object": {"number": input["data"]}}
return output
## option 2
return {"object": {"number": input["data"]}}
(But in reality I would use Ruby 😝 )
05-30-2024 12:05 AM
I don't have experience (yet) with Ruby 😄
def main(input):
# Dictionary to store transport order information based on transport number
transport_order_info_dict = {}
data = input['List']
for row in data:
# Extract relevant fields
transport_number = row['TransportNumber']
order_number = row['OrderNumber']
order_line = row['OrderLine']
order_line_item = row['OrderLineItem']
prim_qty = row['PrimQty']
# Initialize the transport_number entry if not exists
if transport_number not in transport_order_info_dict:
transport_order_info_dict[transport_number] = {}
# Initialize the order_number entry if not exists
if order_number not in transport_order_info_dict[transport_number]:
transport_order_info_dict[transport_number][order_number] = []
# Append the order line item to the corresponding order number
transport_order_info_dict[transport_number][order_number].append({
"OrderLine": order_line,
"OrderLineItem": order_line_item,
"PrimQty": prim_qty
})
# Convert the organized data into the final output structure
output = []
for transport_number, orders in transport_order_info_dict.items():
orders_list = []
for order_number, order_lines in orders.items():
order_lines_list = []
for line in order_lines:
order_lines_list.append({
"PrimQty": line["PrimQty"],
"OrderLineItem": line["OrderLineItem"],
"OrderLine": line["OrderLine"]
})
orders_list.append({
"OrderNumber": order_number,
"OrderLines": order_lines_list
})
output.append({
"TransportOrders": [
{
"Orders": orders_list,
"transport_number": transport_number
}
]
})
# Map the output fields to match the schema
mapped_output = {
"Transportorders": [{"transport_number": transport_number,
"Orders": [{"OrderNumber": order_number,
"OrderLines": [{"PrimQty": line["PrimQty"],
"OrderLineItem": line["OrderLineItem"],
"OrderLine": line["OrderLine"]}
for line in order_lines]}
for order_number, order_lines in orders.items()]}
for transport_number, orders in transport_order_info_dict.items()]
return mapped_output
But when I try to use the output in the next step, the array stays empty.
Might it be that the TransportOrders should be an object instead of an array?
05-30-2024 08:37 AM - edited 05-30-2024 08:38 AM
And I don't know Python 😅
I think it's a case sensitivity issue. Your schema screenshot says "TransportOrders", your output screenshot says "transport_orders", and your script screenshot has "Transportorders"
Workato tends to automatically update CamelCase to snake_case (very annoying, but it's only when displaying input/output) , so I think all you need to do is update your code to "TransportOrders" and you'll be set. Hopefully that works.
05-30-2024 11:59 PM
you are absolutely right.
i got it working. thanks!