Edge: How to interact with Key-Value Map from Javascript Policy?

Not applicable

Is it possible to query/update the Key Value Map from within a JavaScript policy script directly?

Or is it necessary to have an extra KeyValueOperations policy to set the variable first?

Solved Solved
0 5 2,339
1 ACCEPTED SOLUTION

Not applicable

You should use the KeyValueOperations policy first to populate variables into the flow. From there you can consume them with context.getVariable("foo") as with any other variable.

View solution in original post

5 REPLIES 5

Not applicable

You should use the KeyValueOperations policy first to populate variables into the flow. From there you can consume them with context.getVariable("foo") as with any other variable.

Ok, this works.. but it seems needlessly complex?

I can see how that would appear to be the case, but understand that our ability to ensure optimal performance in a highly distributed architecture is to put some "rails on the road".

Not applicable

As @David Allen mentioned the only way to lookup is using the KVM policy .

We can lookup using the management API but using that at runtime from java script is not recommended . However if you use node.js you can store/retrieve variables in cache using apigee-access module but not KVM as of now (Just FYI)

I populated some key-value pairs in a map.

And able to get below output through Management UI API call

https://api.enterprise.apigee.com/v1/organizations...>/environments/test/keyvaluemaps/CounterMap

<KeyValueMap name="CounterMap"> <Entry name="Counter">1</Entry> </KeyValueMap>

After populating values in a KeyValue Map,I tried to access this KeyValue Map in javascript code directly as said by @David Allen in his comments above,

var counter= context.getVariable("Counter")

But its not showing any output.

Note :When I use another KeyValue Map policy to Get the map ,I am able to access it in Javascript.

Keyvalue Map:

<Get assignTo="AnotherVariable" index="1"> <Key> <Parameter>AnotherVar</Parameter> </Key> </Get>

Javascript:

var newvar = parseInt(context.getVariable("AnotherVariable"));

But after just populating in Map,I am not able to access directlyfrom javascript.

Is there a way to refer to a key-value pair in a Map,in Javascript after just putting the values using KeyValue policy?