Scope of a custom variable

Hi All,

I have a question about the scope of a custom variable during the flow of the Proxy. I have a proxy in which i am using a custom variable to define the allowed role/scope for the flow. I am then calling a shared flow to read and validate the incoming JWT token.

What i am seeing is that once the flow execution jumps to the policies inside shared flow , the value of the custom variable is going to null. And when i then try to use the value later by fetching the value in a JS , it comes back as NULL, causing JS to give a run time error.

Can someone point to the documentation ,which states how the variable scope works for a custom variable inside a proxy flow.

Thanks

Chandra

0 6 227
6 REPLIES 6

Not applicable

How are you settling the variable?

If you will create variable using assign message policy assign variable or javascript context.setVariable then you can access that in shared flow using context.getVariable in javascript or simply in the flow as variable. The scope of the variable in this case is every where. Remember not to set the variable in request when using assign message.

I would suggest to use javascript context set and get. This will have scope through out all the flows.

Hi Priyadarshi, Thanks for your answer. I am using Assign Message policy as the first step to set the variable. The value of the value i am setting to one of the API Product's custom variable.

Now issue that i see is when i use a api key verification next and a verify jwt polict after that , somewhere i between then the value of this variable is getting lost. I am using a JS context getVariable later in the flow to extract and spilt the value of this variable , then i get a null error. I believe it is because somewhere along the line one of the policies are populating this var with apiproduct.customeattribute value and not getting the custom attribute value available in context.

Is there any other way i can log the value of this variable at each step in the tracing specifically and debug where exactly its dropping its value ?

Not applicable

You are doing api key verification, so the custom value of the product can be accessed using the

verifyapikey.pilicyname.apiproduct.custom_attrib_name

to get that value.

Same you can get in javascript also like

context.getVariable("verifyapikey.pilicyname.apiproduct.custom_attrib_name");

Hi Priyadarshi,

Thanks for the input , but i would still need to reference the variable using the custom variable ( for example rbac_param ) . So in the assign meesage i am defining the rbac_param as "verifyapikey.policyname.apiproduct.custom_attribute" and then in the JS i am putting two get variable statement in the JS.

This is required because for differnt calls i would need to refernce different custom attribute and therefore their value need to come from tha rbac_param . It is the rbac_param value which seems to be getting dropped off.

Hope i am exaplining it correctly.

Thanks

Chandra

Not applicable

Ok, that's also fine. In a javascript you can set all these to context variables just after the api key verification. Then you can use everywhere in a javascript.

Same can be done using python script also using flow.

thanks , let me try that ...will let know 🙂