I have the oracle database table CASH which contains below columns:
REGISTER DATE CASE BAG TYPE
1234 24-SEP-18 1123 112 A
1234 24-SEP-18 1124 113 S
1234 24-SEP-18 1123 116 S
1234 24-SEP-18 1124 117 A
7895 24-SEP-18 2568 119 A
7895 24-SEP-18 2568 118 S
Where the register number are the cash registers which can have multiple CASE linked to it and each CASE can have more than one BAG and Type attached to it. I want to transform it into below XML in Dataweave:
<ROOT>
<REGISTERS>
<REGISTER>1234</REGISTER>
<DATE>24-SEP-2018</DATE>
<DETAILS>
<BAG>1123</BAG>
<DETAIl>
<BAG>112</BAG>
<TYPE>A</TYPE>
</DETAIl>
<DETAIl>
<BAG>116</BAG>
<TYPE>S</TYPE>
</DETAIl>
</DETAILS>
<DETAILS>
<BAG>1124</BAG>
<DETAIl>
<BAG>113</BAG>
<TYPE>S</TYPE>
</DETAIl>
<DETAIl>
<BAG>117</BAG>
<TYPE>A</TYPE>
</DETAIl>
</DETAILS>
</REGISTERS>
<REGISTERS>
<REGISTER>7895</REGISTER>
<DATE>24-SEP-2018</DATE>
<DETAILS>
<BAG>2568</BAG>
<DETAIl>
<BAG>119</BAG>
<TYPE>A</TYPE>
</DETAIl>
<DETAIl>
<BAG>118</BAG>
<TYPE>S</TYPE>
</DETAIl>
</DETAILS>
</REGISTERS>
</ROOT>
Could you please give some pointers how can I achieve this in dataweave.
Thanks !!
Assuming you've already read the data from the database, you can use the following:
%dw 1.0
%output application/xml
---
ROOT: payload groupBy (($.REGISTER as :string) ++ ($.DATE as :string)) mapObject ((entries, number) -> {
REGISTERS: {
REGISTER: entries[0].REGISTER,
DATE: entries[0].DATE as :string {format: "yyyy-MM-dd"},
(entries groupBy $.CASE map DETAILS: {
CASE: $.CASE[0],
($ map DETAIL: {
BAG: $.BAG,
TYPE: $.TYPE
})
})
}
})
Related
I am trying to return the ErrorReason from the below soap xml response. However it keeps returning empty. I am not sure how to handle the namespace.
I expect to return "The specified envelope has duplicate recipients."
declare #xml xml =
(
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<soap:Header>
<wsa:Action>http://schemas.xmlsoap.org/ws/2004/08/addressing/fault</wsa:Action>
<wsa:MessageID>urn:uuid:b0c43031-35b9-40a1-a217-36491cfdd07c</wsa:MessageID>
<wsa:RelatesTo>urn:uuid:4871a441-ea1e-4f9b-953b-d3f426674597</wsa:RelatesTo>
<wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
<wsse:Security>
<wsu:Timestamp wsu:Id="Timestamp-c41a3e0c-317d-46e2-b203-6a0a43450313">
<wsu:Created>2017-08-31T18:11:00Z</wsu:Created>
<wsu:Expires>2017-08-31T18:16:00Z</wsu:Expires>
</wsu:Timestamp>
</wsse:Security>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>The specified envelope has duplicate recipients. </faultstring>
<faultactor>https://www.test.asmx</faultactor>
<detail>
<ErrorCode xmlns="missing in Web.Config">140</ErrorCode>
<ErrorReason xmlns="missing in Web.Config">The specified envelope has duplicate recipients.</ErrorReason>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>'
)
select x.value('ErrorReason[1]','VARCHAR(max)') from #xml.nodes('/*:Envelope/*:Body/detail') as X(x)
you want the below query
select #xml.query('/*:Envelope/*:Body/*:Fault/*:detail/*:ErrorReason/text()')
Can somebody help me with producing XML from two sql tables?
This is what I want:
<Sales>
<Sale>
<Journal_Prime>400000</Journal_Prime>
<DocNumber>100001</DocNumber>
<Details>
<Detail>
<Account>700300</Account>
<Amount>276,79</Amount>
<DebCre>-1</DebCre>
<Ventil>70</Ventil>
<Ref>WD2093E0V0</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>708000</Account>
<Amount>0,00</Amount>
<DebCre>1</DebCre>
<Ventil>70</Ventil>
<Ref>Korting</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>700530</Account>
<Amount>55,00</Amount>
<DebCre>-1</DebCre>
<Ventil>70</Ventil>
<Ref>Transport</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>451000</Account>
<Amount>0,00</Amount>
<DebCre>-1</DebCre>
<Ventil>11</Ventil>
<Ref>BTW</Ref>
<DocNumber>100001</DocNumber>
</Detail>
</Details>
</Sale>
</Sales>
This is my attempt
SELECT Sale.Journal_Prime, Sale.DocNumber, Detail.Account, Detail.Account, Detail.Amount, Detail.DebCre, Detail.Ventil, Detail.Ref, Detail.DocNumber
FROM XML_FAKAdres2017 as Sale
INNER JOIN XML_FAK2017 as Detail
ON Sale.DocNumber = Detail.DocNumber
FOR XML AUTO, ROOT('Sales'), ELEMENTS
giving me this result
<Sales>
<Sale>
<Journal_Prime>400000</Journal_Prime>
<DocNumber>100001</DocNumber>
<Detail>
<Account>700300</Account>
<Amount>276,79</Amount>
<DebCre>-1</DebCre>
<Ventil>70</Ventil>
<Ref>WD2093E0V0</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>708000</Account>
<Amount>0,00</Amount>
<DebCre>1</DebCre>
<Ventil>70</Ventil>
<Ref>Korting</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>700530</Account>
<Amount>55,00</Amount>
<DebCre>-1</DebCre>
<Ventil>70</Ventil>
<Ref>Transport</Ref>
<DocNumber>100001</DocNumber>
</Detail>
<Detail>
<Account>451000</Account>
<Amount>0,00</Amount>
<DebCre>-1</DebCre>
<Ventil>11</Ventil>
<Ref>BTW</Ref>
<DocNumber>100001</DocNumber>
</Detail>
</Sale>
</Sales>
So, I'm missing the <Details></Details> which is required by the bookkeeping program this code is meant for import. I'm not familiar with XML and to be honest I don't have a clue where this coming from.
Thanks.
Rik
Try this
SELECT Sale.Journal_Prime, Sale.DocNumber ,
(SELECT Detail.Account, Detail.Account, Detail.Amount,
Detail.DebCre, Detail.Ventil, Detail.Ref, Detail.DocNumber
FROM XML_FAK2017 as Detail where Sale.DocNumber = Detail.DocNumber
FOR XML AUTO,TYPE,ROOT('Details'),ELEMENTS)
FROM XML_FAKAdres2017 as Sale
FOR XML AUTO, ROOT('Sales'),ELEMENTS
I'm trying to embed a literal CDATA value in a Mulesoft flow and cannot figure out how to do so.
My desired output (in an HTTP request body) is:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<query xmlns="http://autotask.net/ATWS/v1_5/">
<sXML>
<![CDATA[<queryxml><entity>ticket</entity><query><condition><field>id<expression op="equals">12345</expression></field></condition></query></queryxml>]]>
</sXML>
</query>
</soap:Body>
</soap:Envelope>
My Dataweave transformation looks as follows:
%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope
---
{
soap#Envelope #(version: "1.0") : {
soap#Header: {},
soap#Body: {
query: {
sXML: "<queryxml><entity>ticket</entity><query><condition><field>id<expression op=\"equals\">12345</expression></field></condition></query></queryxml>"
}
}
}
}
But when I send this request to requestb.in (to inspect the contents), I can see it's coming through like this (focus on the sXML entity):
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope" version="1.0">
<soap:Header/>
<soap:Body>
<query>
<sXML><queryxml><entity>ticket</entity><query><condition><field>id<expression op="equals">12345</expression></field></condition></query></queryxml></sXML>
</query>
</soap:Body>
</soap:Envelope>
How can I get a literal CDATA value in there via dataweave / MEL?
Thank you.
I would try:
sXML: "<queryxml> .... </queryxml>" as :cdata
See https://docs.mulesoft.com/mule-user-guide/v/3.8/dataweave-formats#custom-types-2 for more information.
handleInteractiveOrder:
write(vars.subm.soap#Envelope.soap#Body.cp#handleInteractiveOrder,"application/xml")
as CData
in mule 4 we can do like this. I kept my XML in subm variable.
I am facing one issue while xml format conversion in mule transform message.
I am having one input xml file.
and I have to convert the input xml to output xml where the node structure is different and node names are different.
I used data transform message for this conversion, But at one point, it is showing expected format is object and found string.
Can any one please help me for the same.
"Type mismatch
found :name, :string
required :name, :object (com.mulesoft.weave.mule.exception.WeaveExecutionException). Message payload is of type: WeaveMessageProcessor$WeaveOutputHandler"
input payload
<?xml version="1.0" encoding="utf-8"?>
<AGREEMENT>
<details>
<newTransaction>N</newTransaction>
<type>ddd</type>
</details>
</AGREEMENT>
output Payload
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<TestHeader xmlns="TestWebService">
<Username>aaa</Username>
<Password>aaa</Password>
</TestHeader>
</soap:Header>
<soap:Body>
<AGRMNT>
<testId>
<_-Test_Agrmnt- SEGMENT="1">
<transaction>N</transaction>
</__-Test_Agrmnt->
</testId>
</AGRMNT>
</soap:Body>
</soap:Envelope>
DataWeave code
%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope/
{
soap#Envelope: {
soap#Body: {
AGREEMENT: {
testId: {
'_-Test_Agrmnt-': {
transaction: payload.AGREEMENT.details.newTransaction as :string
}
}
}
}}
I have got following output with your input and script
<?xml version='1.0' encoding='UTF-8'?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<AGREEMENT>
<testId>
<_-Test_Agrmnt->
<transaction>N</transaction>
</_-Test_Agrmnt->
</testId>
</AGREEMENT>
</soap:Body>
</soap:Envelope>
The only change is adding --- in script
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/xml
%namespace soap http://schemas.xmlsoap.org/soap/envelope/
---
{
soap#Envelope: {
soap#Body: {
AGREEMENT: {
testId: {
'_-Test_Agrmnt-': {
transaction: payload.AGREEMENT.details.newTransaction as :string
}
}
}
}}}]]>
</dw:set-payload>
</dw:transform-message>
I have an order where the buyer paid the shipping to eBay, however, it's not on the order. It's international shipping and the buyer paid it.
You will see the shipping service cost is $26.15, however, the shipping and handling is $0 in the image. Am I reading the wrong field for shipping?
Request
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Header>
<RequesterCredentials xmlns="urn:ebay:apis:eBLBaseComponents"></RequesterCredentials>
</soap:Header>
<soap:Body>
<GetOrdersRequest xmlns="urn:ebay:apis:eBLBaseComponents">
<DetailLevel>ReturnAll</DetailLevel>
<MessageID>9682099a-9dbd-45b0-a2bb-c9caa4bb42ea</MessageID>
<Version>779</Version>
<OrderIDArray>
<OrderID>161926872948-1351674703006</OrderID>
</OrderIDArray>
</GetOrdersRequest>
</soap:Body>
</soap:Envelope>
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<GetOrdersResponse xmlns="urn:ebay:apis:eBLBaseComponents">
<Timestamp>2016-01-07T19:47:34.216Z</Timestamp>
<Ack>Success</Ack>
<CorrelationID>c310b4b7-b81b-4c9b-ba91-0a434feabf06</CorrelationID>
<Version>949</Version>
<Build>E949_CORE_APIXO_17770993_R1</Build>
<PaginationResult>
<TotalNumberOfPages>1</TotalNumberOfPages>
<TotalNumberOfEntries>1</TotalNumberOfEntries>
</PaginationResult>
<HasMoreOrders>false</HasMoreOrders>
<OrderArray>
<Order>
<OrderID>161926872948-1351674703006</OrderID>
<OrderStatus>Completed</OrderStatus>
<AdjustmentAmount currencyID="USD">0.0</AdjustmentAmount>
<AmountPaid currencyID="USD">56.1</AmountPaid>
<AmountSaved currencyID="USD">0.0</AmountSaved>
<CheckoutStatus>
<eBayPaymentStatus>NoPaymentFailure</eBayPaymentStatus>
<LastModifiedTime>2016-01-07T19:28:25.000Z</LastModifiedTime>
<PaymentMethod>PayPal</PaymentMethod>
<Status>Complete</Status>
<IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled>
</CheckoutStatus>
<ShippingDetails>
<SalesTax>
<SalesTaxPercent>0.0</SalesTaxPercent>
<SalesTaxState></SalesTaxState>
<ShippingIncludedInTax>false</ShippingIncludedInTax>
<SalesTaxAmount currencyID="USD">0.0</SalesTaxAmount>
</SalesTax>
<ShippingServiceOptions>
<ShippingService>ShippingMethodExpress</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>
<ExpeditedService>false</ExpeditedService>
<ShippingTimeMin>1</ShippingTimeMin>
<ShippingTimeMax>4</ShippingTimeMax>
</ShippingServiceOptions>
<InternationalShippingServiceOption>
<ShippingService>InternationalPriorityShipping</ShippingService>
<ShippingServicePriority>1</ShippingServicePriority>
</InternationalShippingServiceOption>
<SellingManagerSalesRecordNumber>74748</SellingManagerSalesRecordNumber>
<TaxTable>
<TaxJurisdiction>
<SalesTaxPercent>8.25</SalesTaxPercent>
<ShippingIncludedInTax>true</ShippingIncludedInTax>
</TaxJurisdiction>
</TaxTable>
<GetItFast>false</GetItFast>
</ShippingDetails>
<CreatedTime>2016-01-04T18:42:01.000Z</CreatedTime>
<PaymentMethods>PayPal</PaymentMethods>
<SellerEmail>Invalid Request</SellerEmail>
<ShippingAddress>
<Name></Name>
<Street1></Street1>
<Street2></Street2>
<CityName></CityName>
<StateOrProvince></StateOrProvince>
<Country>IL</Country>
<CountryName></CountryName>
<Phone></Phone>
<PostalCode>55900</PostalCode>
<ExternalAddressID></ExternalAddressID>
</ShippingAddress>
<ShippingServiceSelected>
<ShippingService>InternationalPriorityShipping</ShippingService>
<ShippingServiceCost currencyID="USD">26.15</ShippingServiceCost>
</ShippingServiceSelected>
<Subtotal currencyID="USD">29.95</Subtotal>
<Total currencyID="USD">56.1</Total>
<ExternalTransaction>
<ExternalTransactionID>XX</ExternalTransactionID>
<ExternalTransactionTime>2016-01-04T18:42:00.000Z</ExternalTransactionTime>
<FeeOrCreditAmount currencyID="USD">1.26</FeeOrCreditAmount>
<PaymentOrRefundAmount currencyID="USD">56.1</PaymentOrRefundAmount>
</ExternalTransaction>
<TransactionArray>
<Transaction>
<Buyer>
<Email>Invalid Request</Email>
<UserFirstName></UserFirstName>
<UserLastName></UserLastName>
</Buyer>
<ShippingDetails>
<CalculatedShippingRate>
<OriginatingPostalCode>63126</OriginatingPostalCode>
<PackageDepth measurementSystem="English" unit="inches">7</PackageDepth>
<PackageLength measurementSystem="English" unit="inches">11</PackageLength>
<PackageWidth measurementSystem="English" unit="inches">1</PackageWidth>
<PackagingHandlingCosts currencyID="USD">0.0</PackagingHandlingCosts>
<ShippingIrregular>false</ShippingIrregular>
<ShippingPackage>PackageThickEnvelope</ShippingPackage>
<WeightMajor measurementSystem="English" unit="lbs">0</WeightMajor>
<WeightMinor measurementSystem="English" unit="oz">3</WeightMinor>
</CalculatedShippingRate>
<SellingManagerSalesRecordNumber>74748</SellingManagerSalesRecordNumber>
</ShippingDetails>
<CreatedDate>2016-01-04T18:42:01.000Z</CreatedDate>
<Item>
<ApplicationData>XX</ApplicationData>
<ItemID>XX</ItemID>
<Site>US</Site>
<Title>Becca Shimmering Skin Perfector - Opal (1.7oz/50ml)....</Title>
<SKU>BECSHIOPA</SKU>
<ConditionID>1000</ConditionID>
<ConditionDisplayName>New</ConditionDisplayName>
</Item>
<QuantityPurchased>1</QuantityPurchased>
<Status>
<PaymentHoldStatus>None</PaymentHoldStatus>
</Status>
<TransactionID>1351674703006</TransactionID>
<TransactionPrice currencyID="USD">29.95</TransactionPrice>
<TransactionSiteID>US</TransactionSiteID>
<Platform>eBay</Platform>
<Taxes>
<TotalTaxAmount currencyID="USD">0.0</TotalTaxAmount>
<TaxDetails>
<Imposition>SalesTax</Imposition>
<TaxDescription>SalesTax</TaxDescription>
<TaxAmount currencyID="USD">0.0</TaxAmount>
<TaxOnSubtotalAmount currencyID="USD">0.0</TaxOnSubtotalAmount>
<TaxOnShippingAmount currencyID="USD">0.0</TaxOnShippingAmount>
<TaxOnHandlingAmount currencyID="USD">0.0</TaxOnHandlingAmount>
</TaxDetails>
<TaxDetails>
<Imposition>WasteRecyclingFee</Imposition>
<TaxDescription>ElectronicWasteRecyclingFee</TaxDescription>
<TaxAmount currencyID="USD">0.0</TaxAmount>
</TaxDetails>
</Taxes>
<ActualShippingCost currencyID="USD">26.15</ActualShippingCost>
<ActualHandlingCost currencyID="USD">0.0</ActualHandlingCost>
<OrderLineItemID>161926872948-1351674703006</OrderLineItemID>
</Transaction>
</TransactionArray>
<PaidTime>2016-01-04T18:42:01.000Z</PaidTime>
<ShippedTime>2016-01-05T18:04:57.000Z</ShippedTime>
<IntegratedMerchantCreditCardEnabled>false</IntegratedMerchantCreditCardEnabled>
<EIASToken>nY+sHZ2PrBmdj6wVnY+sEZ2PrA2dj6AEloWlDpKLpA6dj6x9nY+seQ==</EIASToken>
<PaymentHoldStatus>None</PaymentHoldStatus>
<MonetaryDetails>
<Payments>
<Payment>
<PaymentStatus>Succeeded</PaymentStatus>
<Payer type="eBayUser">XX</Payer>
<Payee type="eBayPartner">XX</Payee>
<PaymentTime>2016-01-04T18:42:00.000Z</PaymentTime>
<PaymentAmount currencyID="USD">26.15</PaymentAmount>
</Payment>
<Payment>
<PaymentStatus>Succeeded</PaymentStatus>
<Payer type="eBayUser">XX</Payer>
<Payee type="eBayUser">XX</Payee>
<PaymentTime>2016-01-04T18:42:00.000Z</PaymentTime>
<PaymentAmount currencyID="USD">29.95</PaymentAmount>
<ReferenceID type="ExternalTransactionID">XX</ReferenceID>
<FeeOrCreditAmount currencyID="USD">1.26</FeeOrCreditAmount>
</Payment>
</Payments>
</MonetaryDetails>
</Order>
</OrderArray>
<OrdersPerPage>100</OrdersPerPage>
<PageNumber>1</PageNumber>
<ReturnedOrderCountActual>1</ReturnedOrderCountActual>
</GetOrdersResponse>
</soapenv:Body>
</soapenv:Envelope>
Because the order is because is using Global Shipping it will show 0.00.
Please check the API documentation on the getordersapi or getmyebayselling api.
Take a look at the tag
<IsMultiLegShipping> boolean </IsMultiLegShipping>
You can exclude these pass through payments if it is true.
In order to see <IsMultiLegShipping> you will need to pass this with your request:
<DetailLevel>ReturnAll</DetailLevel>
DetailLevel: ReturnAll. Also returned if DetailLevel is not provided on input.