Orbeon Forms: Determine Form URL when Form Opens

37 Views Asked by At

We need to determine which environment the form is being generated from via the form URL.

We need this as the form has URLs that call other apps, and these apps can be test, QA or production apps. So, as an example, a form in a test environment needs to call a 3rd party app URL which is also in a test environment:

OrbeonFormTestSystem - 3rdPartyAppTestSystem OrbeonFormQualitySystem - 3rdPartyAppQualitySystem OrbeonFormProductionSystem - 3rdPartyAppProductionSystem

So to do this we need to interrogate the form URL to see which environment is being used. We can do this via the following JavaScript code:

var isProdEnv = window.location.host.includes("prod_indicator");

We then need to use the above result to hide/display the relevant 3rd party app URLs.

I tried using an action using:

<xf:action event="xforms-model-construct-done" type="javascript"> </xf:action>

but this code gets wiped out, and doesn't work with the control xPath to toggle the visibility.

Any assistance would be greatly appreciated.

Regards

PeteA

1

There are 1 best solutions below

3
avernet On

I would advise against using JavaScript to determine the environment, as this approach allows a user to open the console and execute the instruction below with their own value for isProductionSystem, thereby causing the form to mistakenly believe it is in a different environment than its actual one.

ORBEON.xforms.Document.setValue(
    ORBEON.fr.API.findControlsByName(
        "ProductionSystem")[0],
        isProductionSystem
)

Instead, it is better to rely on a formula that runs on the server. One way is to look at the Host header. You could use a hidden control named ProductionSystem with the following Calculated Value formula:

contains(xxf:get-request-header('host'), 'PROD')

Then, in other formulas, you can use:

$ProductionSystem = 'true'