Cannot coerce a:array to an a:object in mule dataweave

14.4k views Asked by At

I am trying to map for multiple SalesOrderLine but getting an error as cannot coerce an array to an object.below is my code..

payload.ORDERS05.*IDOC.E1EDP01 map 
{(

    ns1#SalesOrderCRM: {
    ns0#SalesOrderHeader: {
        ns0#SalesOrderIDs: {
            ns2#ID: payload.ORDERS05.IDOC.E1CUCFG.E1CUPRT.PARENT_ID
        },
        ns0#CustomerParty: {
            ns3#CustomerPartyIDs: {
                ns2#ID: payload.ORDERS05.*IDOC.E1EDP01.E1EDPA1.PARTN[$$]
            },
            ns3#Description: payload.ORDERS05.*IDOC.E1EDP01.E1EDPA1.PARGE[$$],
            ns3#Status: payload.ORDERS05.IDOC.EDI_DC40.STATUS
        }
    },

    ns0#SalesOrderLine: {
        ns0#Description: payload.ORDERS05.*IDOC.E1EDP01.ABGRT[$$],
        ns0#Quantity: payload.ORDERS05.*IDOC.E1EDP01.MENGE[$$],
        ns0#LineNumberID: payload.ORDERS05.*IDOC.E1EDP01.E1EDP20.WMENG[$$],
        ns0#UnitPrice: payload.ORDERS05.*IDOC.E1EDP01.PREIS[$$]
   }
})
}

Please suggest solution for it.

2

There are 2 answers

0
Ryan Hoegg On

The map operator returns an :array, and XML output requires only objects. The {( ... )} syntax converts an array of objects to an object that contains each key value pair (tuple) contained in those objects.

To get past the error you see in the editor, try putting the whole expression within the {( )} nested braces, and see what you get afterward.

Remember that to produce XML, you must output only objects, and that those objects can have more than one key/value pair with the same key. This corresponds to XML nodes. While debugging, it's often handly to change your output to java, and see what you're working with, like so:

%output application/java
0
parteek goyal On

Try Giving the key to this - payload.ORDERS05.*IDOC.E.... like key1 :payload.ORDERS05.*IDOC.E .....