Getting Variables from Request using pythonScript policy

Is it possible to extract variables in requests using the pythonScript policy?
Or must I use ExtractVariable first?

and is it possible to use the variables extracted by the ExtractVariable Policy in another policy?

0 5 697
5 REPLIES 5

Hi Joan,

Please try to use ExtractVariable policy that will help you in easy way.

@Mohsin Khan is it possible to use the variables extracted by the ExtractVariable Policy in another policy?

Yes, that's the usual purpose of invoking ExtractVariables. Once the variables are set by the ExtractVariables policy, you can refer to those variables in Condition elements, or in other policies.

Is it possible to extract variables in requests using the pythonScript policy?

Yes, within pythonScript you can read or write the context variables that are documented here. For example, the syntax to read a variable from pythonScript is:

client_id = flow.getVariable("request.formparam.client_id")

Or must I use ExtractVariable first?

Maybe. Not necessarily. It depends on your requirement. The ExtractVariables policy allows you to extract a new variable from an existing one. Suppose you have a URL Path that is /foo/bar/baz and you would like to extract the middle segment, "bar". ExtractVariables allows you to do that. Or suppose you have a JSON payload and you want to set a variable to contain the value of just one of the fields in the JSON. the ExtractVariables policy can do that for you.

You could also do that in javascript or pythonscript. Or, you could extract via JSON with ExtractVariables, and then read the resulting variables from within pythonscript or javascript. It's up to you.

and is it possible to use the variables extracted by the ExtractVariable Policy in another policy?

Yes. Context variables set by an ExtractVariables policy will be accessible by subsequent policies, including pythonscript policies.

Not applicable

in python script, you can use flow.getVariable.

Yes, you can use extract varibale policy extracted variables in other policies.