Hi everyone, i have a question about extract variable spesific on <VariablePrefix>. this is my code
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-CreateVarResp">
<Source clearPayload="false">response</Source>
<DisplayName>EV-CreateVarResp</DisplayName>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="name">
<JSONPath>$.name</JSONPath>
</Variable>
</JSONPayload>
<VariablePrefix>{message.header.idcustomer}</VariablePrefix>
</ExtractVariables>
can I grab variable existing to initiate variable prefix to the code above? Is it possible to do that? How can I implement this?
the variable result I want is:
cust8371.name
Solved! Go to Solution.
Not with one step. The VariablePrefix element in the ExtractVariables policy does not take a message template. It's a fixed string, so you cannot set a dynamically-determined prefix.
Another way to set a variable is to use AssignMessage and AssignVariable. The syntax for that is:
<AssignMessage name='AM-Example'>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignVariable>
<Name>someName</Name>
<Template>{this-can-be-dynamic}</Template>
</AssignVariable>
...
And there again, the Name element does not accept a template or ref. Like the VariablePrefix element in the ExtractVariables policy, it's a fixed string.
But there is a way to set a variable with a dynamically determined name: the setVariable() call within a JavaScript step.
// assume a prior ExtractVariables step set a variable
// called 'extracted.name'.
// Set a new variable with a fixed name.
context.setVariable('fixed-name',
context.getVariable('extracted.name'));
// Set a new variable with a dynamically-determined name.
context.setVariable(
context.getVariable('message.header.idcustomer'),
context.getVariable('extracted.name'));
Not with one step. The VariablePrefix element in the ExtractVariables policy does not take a message template. It's a fixed string, so you cannot set a dynamically-determined prefix.
Another way to set a variable is to use AssignMessage and AssignVariable. The syntax for that is:
<AssignMessage name='AM-Example'>
<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
<AssignVariable>
<Name>someName</Name>
<Template>{this-can-be-dynamic}</Template>
</AssignVariable>
...
And there again, the Name element does not accept a template or ref. Like the VariablePrefix element in the ExtractVariables policy, it's a fixed string.
But there is a way to set a variable with a dynamically determined name: the setVariable() call within a JavaScript step.
// assume a prior ExtractVariables step set a variable
// called 'extracted.name'.
// Set a new variable with a fixed name.
context.setVariable('fixed-name',
context.getVariable('extracted.name'));
// Set a new variable with a dynamically-determined name.
context.setVariable(
context.getVariable('message.header.idcustomer'),
context.getVariable('extracted.name'));
thanks bro dchiesa1 for your answer, this opened my mind to implement it from another perspective based on your reference. my code now running flawlessly