<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Python snippet - output dictionary to output schema in Workato Pros Discussion Board</title>
    <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6781#M2925</link>
    <description>&lt;P&gt;In my python snippet I have the following output schema defined, which is a nested list:&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pythonsnippet1.JPG" style="width: 713px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1308iD2BD4A6B8AA227D9/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="pythonsnippet1.JPG" alt="pythonsnippet1.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;the output of my python script (when just doing return output) also is in the same format&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pythonsnippet2.JPG" style="width: 445px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1309iDEF760DFC7A573C0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="pythonsnippet2.JPG" alt="pythonsnippet2.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;But for the life of my I cannot figure out how to map the array I created in python on the output schema in the return statement.&lt;/DIV&gt;</description>
    <pubDate>Wed, 29 May 2024 11:42:37 GMT</pubDate>
    <dc:creator>mlamotte</dc:creator>
    <dc:date>2024-05-29T11:42:37Z</dc:date>
    <item>
      <title>Python snippet - output dictionary to output schema</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6781#M2925</link>
      <description>&lt;P&gt;In my python snippet I have the following output schema defined, which is a nested list:&lt;/P&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pythonsnippet1.JPG" style="width: 713px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1308iD2BD4A6B8AA227D9/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="pythonsnippet1.JPG" alt="pythonsnippet1.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;the output of my python script (when just doing return output) also is in the same format&lt;/DIV&gt;&lt;DIV class=""&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pythonsnippet2.JPG" style="width: 445px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1309iDEF760DFC7A573C0/image-size/large/is-moderation-mode/true?v=v2&amp;amp;px=999" role="button" title="pythonsnippet2.JPG" alt="pythonsnippet2.JPG" /&gt;&lt;/span&gt;&lt;/DIV&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;But for the life of my I cannot figure out how to map the array I created in python on the output schema in the return statement.&lt;/DIV&gt;</description>
      <pubDate>Wed, 29 May 2024 11:42:37 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6781#M2925</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-29T11:42:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python snippet - output dictionary to output schema</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6785#M2926</link>
      <description>&lt;P&gt;You don't need to map it in, you just need to create the data to match the schema (exactly) and return it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If my output schema is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="py.png" style="width: 253px;"&gt;&lt;img src="https://systematic.workato.com/t5/image/serverpage/image-id/1310iCECFAD55BA3B564A/image-dimensions/253x183/is-moderation-mode/true?v=v2" width="253" height="183" role="button" title="py.png" alt="py.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Then this is how I will return:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def main(input):
  ## option 1
  output = {"object": {"number": input["data"]}}
  return output

  ## option 2
  return {"object": {"number": input["data"]}}&lt;/LI-CODE&gt;&lt;P&gt;(But in reality I would use Ruby &lt;span class="lia-unicode-emoji" title=":squinting_face_with_tongue:"&gt;😝&lt;/span&gt; )&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 14:58:46 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6785#M2926</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-05-29T14:58:46Z</dc:date>
    </item>
    <item>
      <title>Re: Python snippet - output dictionary to output schema</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6791#M2931</link>
      <description>&lt;P&gt;I don't have experience (yet) with Ruby &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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&lt;/LI-CODE&gt;&lt;P&gt;But when I try to use the output in the next step, the array stays empty.&lt;BR /&gt;Might it be that the TransportOrders should be an object instead of an array?&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 07:05:27 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6791#M2931</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-30T07:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: Python snippet - output dictionary to output schema</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6794#M2933</link>
      <description>&lt;P&gt;And I don't know Python&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face_with_sweat:"&gt;😅&lt;/span&gt;&lt;/P&gt;&lt;P&gt;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"&amp;nbsp;&lt;/P&gt;&lt;P&gt;Workato tends to automatically update CamelCase to snake_case (very annoying, but it's only when &lt;EM&gt;displaying&lt;/EM&gt; input/output) , so I think all you need to do is update your code to "TransportOrders" and you'll be set. Hopefully that works.&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 15:38:34 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6794#M2933</guid>
      <dc:creator>gary1</dc:creator>
      <dc:date>2024-05-30T15:38:34Z</dc:date>
    </item>
    <item>
      <title>Re: Python snippet - output dictionary to output schema</title>
      <link>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6796#M2935</link>
      <description>&lt;P&gt;you are absolutely right.&lt;BR /&gt;i got it working. thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 06:59:16 GMT</pubDate>
      <guid>https://systematic.workato.com/t5/workato-pros-discussion-board/python-snippet-output-dictionary-to-output-schema/m-p/6796#M2935</guid>
      <dc:creator>mlamotte</dc:creator>
      <dc:date>2024-05-31T06:59:16Z</dc:date>
    </item>
  </channel>
</rss>

