Search code examples
dataweavemule4

How to read value from property file from inside a select query in DW 2


I am trying to read table name from property file instead of reading it from a variable. Currently I am doing the below and its working, but I want to externalize the table name and read it from property file instead

entry in property file tablename = employee

Dataweave:

'SELECT * FROM $(vars.tableName) WHERE id=123'

I tried below and many others but not working:

'SELECT * FROM $(tablename) WHERE id=123'

'SELECT * FROM p('secure::tablename') WHERE id=123'

Could you please help.


Solution

  • Ideally, you should use the p() function to read property values in DataWeave expressions. As you trying to construct a query with a property value, use should surround the p() function in $().

    For Example

    SELECT * FROM $(p('tablename')) WHERE id=123

    Make sure to include the property placeholder key-value pairs in the property file and reference them using the global configuration properties element.