Can Flow Variables be set using Resource Files at an organisation or a environment level ?

If a javascript resource file sets the flow variables as follows :

context.setVariable("varname1", "value1"); 
var host = "hostname.com"; 
var contextRoot = "/" + context.getVariable("request.path").split('/').slice(1,3).join('/'); 
var client_id = ""; 
var client_secret = ""; 
var organization = context.getVariable("organization.name"); 
var environment = context.getVariable("environment.name"); 
var proxyName = context.getVariable("apiproxy.name"); 
var proxyRevision = context.getVariable("apiproxy.revision"); 

//proxy.name 

switch(environment) { 
  case "sandbox": 
    client_id = “xxxxxxxxxxxxxxxx”; 
    break;
  case "prod" :
    and so on..
}

context.setVariable("query-host", host); 
context.setVariable("query-path", organization + "-" + environment + "/api-gateway/configs/"); 
context.setVariable("client-id", client_id); 

This seems to take effect at the api proxy level, but not when used as a resource file at the environment or org level.

So, Can Flow variables be set at the env. or org level ?

Solved Solved
1 2 366
1 ACCEPTED SOLUTION

vijay
Participant I

Yes, flow variables can be set from within JavaScript source files. Often, the JavaScript is packaged as a resource file in the API Proxy itself. But a JavaScript module can also be uploaded as an environment-wide resource, or an organization-wide resource. Regardless where the JS module is anchored, execution of the JS works the same way.

You can refer to the org-scoped or env-scoped javascript resource files in the JS policy, in the same way that you refer to a proxy-scoped resource file.

<Javascript name='JS-SetResponse' timeLimit='200' >
  <Properties>
    <Property name='prop1'>value-here</Property>
  </Properties>
  <ResourceURL>jsc://setResponse.js</ResourceURL>
</Javascript>

In the above, the policy will first look for the setResponse.js file in the apiproxy, then in the set of environment-scoped resources, and finally in the set of organization-scoped resources.

View solution in original post

2 REPLIES 2

vijay
Participant I

Yes, flow variables can be set from within JavaScript source files. Often, the JavaScript is packaged as a resource file in the API Proxy itself. But a JavaScript module can also be uploaded as an environment-wide resource, or an organization-wide resource. Regardless where the JS module is anchored, execution of the JS works the same way.

You can refer to the org-scoped or env-scoped javascript resource files in the JS policy, in the same way that you refer to a proxy-scoped resource file.

<Javascript name='JS-SetResponse' timeLimit='200' >
  <Properties>
    <Property name='prop1'>value-here</Property>
  </Properties>
  <ResourceURL>jsc://setResponse.js</ResourceURL>
</Javascript>

In the above, the policy will first look for the setResponse.js file in the apiproxy, then in the set of environment-scoped resources, and finally in the set of organization-scoped resources.

Not applicable

Within each proxy you would need to execute the org or enviro resource file for those variables to be available in that message flow.

In other words, you will have to add the step in each of your proxies to get the benefit of the any variables set in that step.