Reputation: 8311
I want to store an expression in flow variable and want to retrieve it as same that I stored.... For example :-
<set-variable doc:name="Variable" value="#[xpath('//v1:insertDataRequest/v1:Id').text]" variableName="cacheKey"/>
Here in the flow variable called cacheKey I want to store the expression #[xpath('//v1:insertDataRequest/v1:Id').text]
as a String so that if I want to retrieve it such as following
<logger message="#[flowVars['cacheKey']" level="INFO" doc:name="Logger"/>
It should retrieve me the value of #[flowVars['cacheKey']
as #[xpath('//v1:insertDataRequest/v1:Id').text]
as a String
But in my case whenever I am trying to store
<set-variable doc:name="Variable" value="#[xpath('//v1:insertDataRequest/v1:Id').text]" variableName="cacheKey"/>
It is extracting the xpath value with current message payload and I am getting the extracted value of xpath from payload instead of getting #[xpath('//v1:insertDataRequest/v1:Id').text]
So, my question is how can I store the value #[xpath('//v1:insertDataRequest/v1:Id').text]
as a String in flowVars so that I get exactly #[xpath('//v1:insertDataRequest/v1:Id').text]
as flowVars value and not extracted value of xpath
Please help
Upvotes: 0
Views: 3081
Reputation: 8311
So finally as Nuno suggested, the working solution is :-
<set-variable doc:name="Variable" value="#['#[xpath(\'//v1:insertDataRequest/v1:Id\').text]']" variableName="cacheKey"/>
Upvotes: 0
Reputation: 5115
There is no such thing as an eval that reuses the current context in MVEL, and therefor even if you get to store the value as per ~nuno (or just separating somehow the # from the [, perhaps with string appenders) you won't be able to execute it.
I can't see the big picture of your problem, but with what I can guess I would use rather than this a property placeholder with the expressions you need to be able to customise.
For the part of the questions, where you point that you don't wan't to loose the payload, just use an enritcher, it's designed exactly for that and anyone reading it will quickly understand what you were trying to do.
Upvotes: 1
Reputation: 496
This should work:
<set-variable doc:name="Variable" value="#['#[xpath('//v1:insertDataRequest/v1:Id').text]']" variableName="cacheKey"/>
EDIT:
Apostrophes should be escaped
<set-variable doc:name="Variable" value="#['#[xpath(\'//v1:insertDataRequest/v1:Id\').text]']" variableName="cacheKey"/>
Upvotes: 1
Reputation: 6530
You can replace set-variable tag by:
<expression-component>
flowVars.cacheKey = "#[xpath('//v1:insertDataRequest/v1:Id').text]";
</expression-component>
Upvotes: -1