I have written a KVMap in my Apigee as follows:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <KeyValueMapOperations async="false" continueOnError="false" enabled="true" name="GlobalKeyValue"> <DisplayName>GlobalKeyValue</DisplayName> <ExpiryTimeInSecs>-1</ExpiryTimeInSecs> <InitialEntries> <Entry> <Key> <Parameter>Key</Parameter> </Key> <Value>ba91d757742d31ee8c5617de528b9dcaa639e459d971ad3ff08145ccb09b15a3b7249afb72508372d28ae0921ede44d787f7a8fce31c6758f4a9007ad9015ce2</Value> </Entry> <Entry> <Key> <Parameter>Counter</Parameter> </Key> <Value>7589027556679898845</Value> </Entry> </InitialEntries> <Scope>environment</Scope> </KeyValueMapOperations>
My purpose is to use Global Variables and therefore and I using <Scope>environment</Scope> element. I would now want to access these variables in ServiceCallout policy and Javascript. How can I do that?
Solved! Go to Solution.
The <InitialEntries> does the action of storing the key/value alone. you need to do a <Get> operation (as shown below) in the policy to make the values available as flow variables.
<Get assignTo="Key"> <Key> <Parameter>Key</Parameter> </Key> </Get> <Get assignTo="Counter"> <Key> <Parameter>Counter</Parameter> </Key> </Get>
It should be simple & straight forward,
var newVariable = context.getVariable("VARIABLENAME");
{VARIABLENAME}
More details you can find in doc pages.
Thanks for the quick reply.
I tried using this in ServiceCallout:
{Key} and {Counter}
I am still unable to identify the variable. The error is unresolved variable
The <InitialEntries> does the action of storing the key/value alone. you need to do a <Get> operation (as shown below) in the policy to make the values available as flow variables.
<Get assignTo="Key"> <Key> <Parameter>Key</Parameter> </Key> </Get> <Get assignTo="Counter"> <Key> <Parameter>Counter</Parameter> </Key> </Get>
Thankyou so much @sribalaji
It worked. I am also intending to set the Key Value Map Global variable in a Javascript later ahead in the chain.
I tried using context.setVariable("Counter", counter).
The code executes just fine except that the variable is not updated. Am I doing anything wrong here?
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |