Map nested json array into CSV - mule

I am trying to map an array payload into CSV in Dataweave and not able to achieve the result.
The csv will not need header, the content in the array will print in column by column. I'm facing problem to make the mapping through the nested array.
Input payload
[
{
"Invoice": {
"Invoice Number*": "Test",
"Supplier Number": "1201",
"Submit For Approval?": "Yes",
"Invoice Date*": "20190828",
"Line Level Taxation*": "Yes",
"Payment Date": "00/00/0000",
"Original invoice number": "",
"Original invoice date": ""
},
"Invoice Line": [
{
"Invoice Number*": "Test1",
"Line Number": "1",
"Description*": "Test1",
"Price*": "500",
"Quantity": null,
"Unit of Measure*": null,
"PO Number": "001",
"PO Line Number": "1"
},
{
"Invoice Number*": "Test2",
"Line Number": "2",
"Description*": "Test2",
"Price*": "500",
"Quantity": null,
"Unit of Measure*": null,
"PO Number": "001",
"PO Line Number": "2"
}
],
"Invoice Tax Line": [
{
"Tax Amount": "500",
"Invoice Line Number": "1",
"Line Number": "1"
},
{
"Tax Amount": "50",
"Invoice Line Number": "2",
"Line Number": "2"
}
]
}
]
Expected Output
column_0, column_1, column_2 ... //no header
"Invoice Number*","Supplier Number","Submit For Approval?"... //Invoice
"Invoice Number*","Line Number*"... //InvoiceLine[0]
"Tax Amount","Invoice Line Number","Line Number"... //Tax Line[0]
"Invoice Number*","Line Number*"... //InvoiceLine[1]
"Tax Amount","Invoice Line Number","Line Number"... //Tax Line[1]
How can i write the dataweave mapping to archive the result like above?

This is the solution I found for your use case. Basically there are two functions to that dispatches on the right method according to the type. And then you also want to use zip function to mix one "Invoice Line" with one "Invoice Tax Line" so they are mixed correctly.
%dw 2.0
output application/csv headers=false
import * from dw::core::Objects
fun collectKeyNames(obj: {}): Array<{}> =
[
obj
]
fun collectKeyNames(arr: Array): Array<{}> =
arr flatMap ((obj, index) -> collectKeyNames(obj))
---
payload flatMap ((item, index) ->
collectKeyNames(item.Invoice) ++
(collectKeyNames(item."Invoice Line" zip item."Invoice Tax Line"))
)

Related

DataWeave unflatten mapping

Need some help in writing DataWeave for this Salesforce payload.
Please help with creating a DataWeave for this input and expected output.
INPUT
[
{
"Order": {
"Account_Name__c": "test danish 002",
"Id": "8018s000004mpqjAAA",
"type": "Order"
},
"UnitPrice": "13.45",
"Product2": {
"Id": null,
"type": "Product2",
"Name": "* 1 LEG FOR MESAHORNO STAND110"
},
"Id": "8028s000000kyUDAAY",
"type": "OrderItem",
"OrderItemNumber": "0000051590"
},
{
"Order": {
"Account_Name__c": "test danish 002",
"Id": "8018s000004mpqjAAA",
"type": "Order"
},
"UnitPrice": "308.45",
"Product2": {
"Id": null,
"type": "Product2",
"Name": "* 2 Uprights incl castors f RTWZ 600 Var"
},
"Id": "8028s000000kyUEAAY",
"type": "OrderItem",
"OrderItemNumber": "0000051591"
},
{
"Order": {
"Account_Name__c": "test danish 002",
"Id": "8018s000004mpqjAAA",
"type": "Order"
},
"UnitPrice": "31.0",
"Product2": {
"Id": null,
"type": "Product2",
"Name": "* 25 Comp Glass Rack - 3 Ext - Red Base"
},
"Id": "8028s000000kyUFAAY",
"type": "OrderItem",
"OrderItemNumber": "0000051592"
},
{
"Order": {
"Account_Name__c": "test danish 002",
"Id": "8018s000004mpqjAAA",
"type": "Order"
},
"UnitPrice": "31.65",
"Product2": {
"Id": null,
"type": "Product2",
"Name": "* 36 Comp Glass Rack 3 Ext - Gray"
},
"Id": "8028s000000kyUGAAY",
"type": "OrderItem",
"OrderItemNumber": "0000051593"
}
]
This is the Salesforce Query on OrderLineItems but the transformed payload needs to be done on Order Object
and the output would look like
Output
{
"Id":"8018s000004mpqjAAA",
"Order Name": "test danish 002",
"Line Items": [
{
"Id":"8028s000000kyUDAAY",
"ItemNumber":"0000051590",
"Name":"* 1 LEG FOR MESAHORNO STAND110"
},
{
"Id":"8028s000000kyUEAAY",
"ItemNumber":"0000051591",
"Name":"* 2 Uprights incl castors f RTWZ 600 Var"
},
{
"Id":"8028s000000kyUFAAY",
"ItemNumber":"0000051592",
"Name":"* 25 Comp Glass Rack - 3 Ext - Red Base"
},
{
"Id":"8028s000000kyUGAAY",
"ItemNumber":"0000051593",
"Name":"* 36 Comp Glass Rack 3 Ext - Gray"
}
]
}
Try like this:
%dw 2.0
output application/json
---
{
"Id" : payload[0].Order.Id,
"Order Name": payload[0].Order.Account_Name__c,
"Line Items" : payload map{
Id: $.Id,
ItemNumber : $.OrderItemNumber,
"Line Items" : $.Product2.Name
}
}
Assuming that all the order IDs are same you can just map the Id directly from payload and use the map on payload to get the Line Items
%dw 2.0
output application/json
---
{
Id: payload[0].Order.Id,
"Order Name": payload[0].Order.Account_Name__c,
"Line Items": payload map {
Id: $.Id,
ItemNumber: $.OrderItemNumber,
Name: $.Product2.Name
}
}
Here is one more option that you can try when ordered Id's are not the same
%dw 2.0
output application/json
---
payload groupBy ((item, index) -> item.Order.Id)
mapObject ((value, key, index) ->
{"Id": value.Order.Id[0],
"Order Name": value.Order.Account_Name__c[0],
"Line Items": value map ({
Id: $.Id,
ItemNumber: $.OrderItemNumber,
Name: $.Product2.Name
})}
)

DocuSign API explorer - does not recognize tabs for Signature

I'm using the DocuSign API explorer to test the use of tabs for signature. I've created a Word document with a placeholder called /InternSignatureAnchor/ enter image description here
And the JSON request payload looks like this:
{
"documents": [
{
"documentBase64": "<Base64BytesHere>",
"documentId": "123456",
"fileExtension": "DOCX",
"name": "Freelance Contract"
}
],
"emailSubject": "Please Sign Contracts 3",
"recipients": {
"signers": [
{
"email": "dummy_email123#mmmm.mmm",
"name": "Dummy Recipient 1",
"recipientId": "1",
"roleName": "Internal Signatory",
"routingOrder": "1",
"tabs": {
"signHereTabs": [
{
"documentId": "123456",
"pageNumber": "1",
"tabLabel": "/InternSignatureAnchor/",
"xPosition": "0",
"yPosition": "36"
}
]
}
},
{
"email": "dummy_email321#mmmmm.mmm",
"name": "Dummy recipient 2",
"recipientId": "2",
"roleName": "External Signatory",
"routingOrder": "2"
}
]
},
"status": "sent"
}
When the signatory opens the document to sign, the "Sign" enter image description here
is not placed at the placeholder /InternSignatureAnchor/. When I use the Autoplace feature in DocuSign itself, it does work.
Anyone an idea?
Thanks in advance.
The "tagLabel" will just add a label to a tag. To use AutoTagging you'd need to use a json like below:
"tabs": {
"signHereTabs": [{
"anchorString": "Please Sign Here",
"anchorXOffset": "1",
"anchorYOffset": "0",
"anchorIgnoreIfNotPresent": "false",
"anchorUnits": "inches"
}]
}
I believe API explorer does not show the fields for auto tagging currently - so you'd need to perhaps use Postman to play around with this feature.

Mulesoft transform multiple JSON/XML to CSV

I'm totally new on transforming JSON to CSV in Mulesoft. Currently i need to work on to transform a nested JSON into CSV which my CSV should look like this and my JSON will be like
{
"Invoice": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Status": "",
"Invoice Date*": ""
}
],
"Invoice Line": [
{
"Invoice Number*": "",
"Supplier Name": "",
"Supplier Number": "",
"Line Number": "",
"Description*": "",
"Supplier Part Number": "",
"Auxiliary Part Number": "",
"Price*": "",
"Quantity": "",
"Bulk Price": "",
"Bulk Price Qty": ""
}
],
"Invoice Tax Line": [
{
"Invoice Number*": "",
"Invoice Line Number": "",
"Invoice Charge Number": "",
"Line Number": "",
"Tax Amount": "",
"Tax Rate": "",
"Tax Code": "",
"Tax Rate Type": ""
}
]
}
What i know about CSV is there will be only one header. What is the best way for me to map this complex JSON into CSV which will shows different header?
You can do something like this:
%dw 2.0
output application/csv header=false
---
flatten (
[
{"Invoice Number":"Invoice Number",
"Supplier Name": "Supplier Name",
"Supplier Number" :"Supplier Number",
"Status" : "Status",
"Invoice Date*" : "Invoice Date*"
},
{
"Invoice Number":"Invoice Number*",
"Supplier Name":"Supplier Name",
"Supplier Number":"Supplier Number",
"Status":"Status",
"Invoice Date*":"Invoice Date*"
},
payload.Invoice map {
"Invoice Number":$."Invoice Number*",
"Supplier Name":$."Supplier Name",
"Supplier Number":$."Supplier Number",
"Status":$.Status,
"Invoice Date*":$."Invoice Date*"
},
payload."Invoice Line" map {
"Invoice Number": $."Invoice Number*",
"Supplier Name":$."Supplier Name",
...
}
,
payload."Invoice Tax Line" map {
"Invoice Number":$."Invoice Number*",
...
}
]
)

How to specify product IDs in Google Search "application/ld+json" script without getting "Missing product ID (optional)"

How can I reduce warning of "Missing product ID (optional)" on "application/ld+json" script in google search console?
Below My sample JSON-LD code
<script type="application/ld+json">
{
"#context": "http://schema.org/",
"#type": "Product",
"name": "done product Name here",
"url": "done product url here",
"image": [
"done image url here"
],
"description": "done description here",
"sku": "H100000001",
"productID" : "9876543210", // Added like this type behaviour
"brand": {
"#type": "Thing",
"name": "cosmetics"
},
"offers": [{
"#type" : "Offer",
"sku": "H100000002",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
},
{
"#type" : "Offer",
"sku": "H100000003",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
},
{
"#type" : "Offer",
"sku": "H099020004",
"availability" : "http://schema.org/InStock",
"price" : "26.0",
"priceCurrency" : "USD",
"url" : "product url"
}]
}
</script>
I have tried different variables of product id below
1. "productID" : "9876543210",
2. "productID" : "isbn:9876543210",
3. "product-id" : "isbn:9876543210",
4. "product-id" : "9876543210",
but error still getting.
Can anyone help how can I solve the issue of Missing product ID (optional)" on Google Search Console?
Which behavior is correct for set product id in ld+json?
The message from Google is not very clear... what it's looking for is one of product IDs from https://schema.org/Product (gtin13, etc.). I was getting the same error after adding ProductID, but once I replaced ProductID with the gtinxxx values, the warning went away.

Split multi valued cells in more than one column into rows (Open Refine)

I have been cleaning a table on Open Refine. I now have it like this:
REF Handle Size Price
2002, 2003 t-shirt1 M, L 23
3001, 3002, 3003 t-shirt2 S, M, L 24
I need to split those multivalued cells in REF and Size so that I get:
REF Handle Size Price
2002 t-shirt1 M 23
2003 t-shirt1 L 23
3001 t-shirt2 S 24
3002 t-shirt2 M 24
3003 t-shirt2 L 24
Is it possible to do this in Open Refine? The "Split multi-valued cells..." command only takes care of one column.
Thank you,
Ana Rita
Yes, it's possible :
Split the 1st column using ", " as separator.
Move column 2 at position one
display your project as record (not row)
Split column 3 using ", " as separator
Fill down columns 4 and 2
reorder columns
Here's my recipe in GREL :
[
{
"op": "core/row-removal",
"description": "Remove rows",
"engineConfig": {
"facets": [
{
"invert": false,
"expression": "row.starred",
"selectError": false,
"omitError": false,
"selectBlank": false,
"name": "Starred Rows",
"omitBlank": false,
"columnName": "",
"type": "list",
"selection": [
{
"v": {
"v": true,
"l": "true"
}
}
]
}
],
"mode": "row-based"
}
},
{
"op": "core/multivalued-cell-split",
"description": "Split multi-valued cells in column Column 1",
"columnName": "Column 1",
"keyColumnName": "Column 1",
"separator": ", ",
"mode": "plain"
},
{
"op": "core/column-move",
"description": "Move column Column 2 to position 0",
"columnName": "Column 2",
"index": 0
},
{
"op": "core/multivalued-cell-split",
"description": "Split multi-valued cells in column Column 3",
"columnName": "Column 3",
"keyColumnName": "Column 2",
"separator": ", ",
"mode": "plain"
},
{
"op": "core/fill-down",
"description": "Fill down cells in column Column 4",
"engineConfig": {
"facets": [],
"mode": "record-based"
},
"columnName": "Column 4"
},
{
"op": "core/fill-down",
"description": "Fill down cells in column Column 2",
"engineConfig": {
"facets": [],
"mode": "record-based"
},
"columnName": "Column 2"
},
{
"op": "core/column-reorder",
"description": "Reorder columns",
"columnNames": [
"Column 1",
"Column 2",
"Column 3",
"Column 4"
]
}
]
Hervé
Just found a nice, free OpenRefine plugin that offers "Unpaired pivot":
VIB-Bits plugin
From their documentation:
3.2.1 Unpaired pivot...
Unpaired pivot is the transformation of data that is organized in rows to a representation of that
data in separate columns. A simple example would be transforming
Category
Value
a
1
a
2
b
3
c
2
into
Value a
Value b
Value c
1
3
2
2