Reputation: 1858
I am trying to figure out how to get values from the returned Search payload using the NetSuite Connector in Mulesoft.
Whenever I use this connector, it returned an output of List<Map<String, Object>>
, I am unsure if there is a way to use DataWeave and map the values returned, because of this type of output.
Is there a way to actually get the components of this List, and map it to something else using Dataweave?
In one example, I am grabbing the internalId of a search result record using #[payload.hasNext() ? 'Employee Found: ' + payload.next().get('internalId') : 'Employee Not Found']
and I can successfully get the value.
In another case where I am trying to use that internalId with the NetSuite Connector 'Get Record' functionality, I try to input an internalId parameter payload.next().get('internalId')
the same way and get an error as follows.
<netsuite:get-record config-ref="NetSuite_Login_Auth" internalId="#[payload.next().get('internalId')]" type="EMPLOYEE" doc:name="NetSuite"/>
ERROR:
Message : Failed to invoke getRecord. Payload
: org.mule.streaming.ConsumerIterator@20969555 Payload Type : org.mule.streaming.ConsumerIterator Element : /streamMigrateAccountToCustomer/processors/10/0/1/0/1/searchEmployeeByEntityId/subprocessors/3/1/0 @ sfdc-netsuite-api Element XML : -------------------------------------------------------------------------------- Root Exception stack trace: java.util.NoSuchElementException at org.mule.streaming.AbstractConsumer.consume(AbstractConsumer.java:70) at org.mule.streaming.ConsumerIterator.next(ConsumerIterator.java:60) at sun.reflect.GeneratedMethodAccessor148.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source)
Upvotes: 0
Views: 1051
Reputation: 797
You can get the values and pass it inside a batch execute and do the mapping inside the batch
<flow name="swt-ns-data-pull">
<dw:transform-message doc:name="Transform Message">
<dw:set-payload><![CDATA[%dw 1.0
%output application/java
---
{
basic: {
lastModifiedDate: {
operator: "AFTER",
searchValue: flowVars.modifiedDate
},
recordType: {
operator: "IS",
searchValue: "vendorPayment"
}
}
} as :object {
class : "com.netsuite.webservices.transactions.sales.TransactionSearch"
}
]]></dw:set-payload>
</dw:transform-message>
<logger message="started" level="INFO" doc:name="Logger"/>
<netsuite:search config-ref="NetSuite__Request_Level_Token_Based_Authentication" searchRecord="TRANSACTION" bodyFieldsOnly="false" fetchSize="1000" doc:name="NetSuite"/>
</flow>
Mapping Inside batch
<batch:step name="RemittanceDetailCreation">
<json:object-to-json-transformer doc:name="Object to JSON"/>
<batch:set-record-variable variableName="rec" value="#[payload]" doc:name="Record Variable"/>
<dw:transform-message metadata:id="b7f75c92-a6c7-423a-8faa-cb9080914888" doc:name="Transform Message">
<dw:input-payload mimeType="application/json" doc:sample="C:\Users\sathekumar\Desktop\VedorPayment.json"/>
<dw:set-payload><![CDATA[%dw 1.0
%output application/csv header = false
%var NIC=sizeOf payload.applyList.apply
---
payload.applyList.apply map (( payment, indexOfPayment) ->{
NumberInCollection: '"' ++ NIC ++ '"' when NIC != null otherwise null,
ExternalPayableReferenceNumber: null,
ExternalSecondaryPayableReferenceNumber: null,
AdjustmentAmount: null,
DiscountAmount: '"' ++ payment.discAmt ++ '"' when payment.discAmt != null otherwise null,
GrossAmount: '"' ++ (payment.total as :string) ++ '"' when payment.total != null otherwise null,
NetAmount: '"' ++ (payment.amount as :string) ++ '"' when payment.amount != null otherwise null,
PayableDate: payload.PayableDate,
PayableReferenceNumber: paylaod.PR,
PayableType: null,
SecondaryPayableReferenceNumber: null,
SecondaryPayableType: null,
SupplierPayableReferenceNumber: null
})]]></dw:set-payload>
</dw:transform-message>
<byte-array-to-string-transformer doc:name="Byte Array to String"/>
<batch:commit size="1000" doc:name="Batch Commit">
Upvotes: 1
Reputation: 669
Is there a way to actually get the components of this List, and map it to something else using Dataweave?
It is currently not possible. The Search operation returns a list of Map<String, Object>
without any additional metadata thus making it impossible for DataWeave to identify which components are included. I'm not sure if this responds to a limitation of the NetSuite SOAP API or it just hasn't been implemented in the connector.
In another case where I am trying to use that internalId with the NetSuite Connector 'Get Record' functionality, I try to input an internalId parameter payload.next().get('internalId') the same way and get an error as follows.
The Search operation works because it is a paginated operation that wraps the payload inside a ConsumerIterator
object. However, the Get Record is NOT paginated and just returns a Map<String, Object>
. Therefore, you should be able to obtain the value by calling payload.get('internalId')
.
Upvotes: 0