hc0re
hc0re

Reputation: 1986

How to use configuration parameters in DataWeave 2 transform scripts?

Let's say that I have a configuration file called error-messages.properties. In this file I have a property:

error.invoice.missing.creationDate

When I'm trying to directly input this parameter into DataWeave script, like

"${error.invoice.missing.creationDate}"

I get an error in the script:

Unable to resolve reference of: `$`.

When I'm doing it like this:

"\${error.invoice.missing.creationDate"

I get no errors in the script, but when I am trying to run this code, I get the same error just a liitle bit later:

import fail from dw::Runtime

output application/java
ns ns0 com.app.invoice/Invoice
var isPresent = (value, message: String) -> if (value == null or isEmpty(value)) fail(message) else value
---
{
    creationDate: isPresent(payload.invoice.creationTime, "${error.invoice.missing.creationDate}")
} as Object {
    class : "domain.command.InvoiceCommand"
} ' has errors: 
    Unable to resolve reference of $. at 9 : 9" evaluating expression: "%dw 2.0

How can I put my variables into the DW script correctly? I know that "${some.param}" works in XML files, but how to do it in DW2.0 scripts?

Upvotes: 1

Views: 1745

Answers (1)

Salim Khan
Salim Khan

Reputation: 4303

Use the p() function to refer to config properties.

https://help.mulesoft.com/s/article/How-to-read-external-property-in-DataWeave

Upvotes: 4

Related Questions