How do I access Key Value Map element into a ServiceCallout policy and Javascript policy?

Not applicable

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 Solved
0 4 881
1 ACCEPTED 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>

View solution in original post

4 REPLIES 4

@apigee1234567 ,

It should be simple & straight forward,

var newVariable = context.getVariable("VARIABLENAME");

{VARIABLENAME}

More details you can find in doc pages.

@Anil Sagar

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?