Reusable Javascript Variables

In our Use case , we are using 2+ JavaScript policies at different places in the proxy flow.Wherein we are using context.getVariable() in all the Js ploicy to get the extracted variables.

  1. Is there a way that we can implement to avoid redundancy of getting the same variables in all JS?
  2. Can we implement Like this (Is that a best Practice)?

    Use a library Js where we can define the function which has all the getVariables and then call that function in all the JS

Example: library Js

function getVariables(){

	var Var1 = context.getVariable("Variable1");

	var Var2  = context.getVariable("Variable2");

}
1 3 353
3 REPLIES 3

@maivizhi , See similar question asked here, let us know if it solves same.

Thanks @Anil Sagar for the info.

It worked !

we can reuse context.getVariable() too without defining it inside a separate function.

Example : library Js

var Var1 = context.getVariable("Variable1");
var Var2 = context.getVariable("Variable2");


function function1()
{
}

The variable Var1,Var2 and Function function1() can be reused in any Js within the Proxy.

Hope i am correct!

@maivizhi , Awesome, Glad it worked 🙂