When developers want to generate APEX URL from a JavaScript the thing that most of them will do is to concatenate URL string like this:
But there's one (unfortunately) undocumented feature that you can use to make it easier. It's possible to do it by using apex.util.makeApplicationUrl function that excepts a JavaScript object as the only parameter. In that object, you can define all that is needed to generate an APEX URL.
Here is an example:
Note: the function will not generate the checksum for pages or items with session state protection turned on.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vItemValue = 'New Item Value'; | |
// Example 1 - get URL to set item value on page 1 with value from variable vItemValue | |
var vUrl = "f?p=" + $v( "pFlowId" ) + ":1:" + $v( "pInstance" ) + "::" + $v( "pdebug" ) + "::P1_ITEM:"+vItemValue; | |
// Example 2 - get URL to set item value on current page with value from variable vItemValue | |
var vUrl = "f?p=" + $v( "pFlowId" ) + ":" + $v( "pFlowStepId" ) + ":" + $v( "pInstance" ) + "::" + $v( "pdebug" ) + "::P1_ITEM:"+vItemValue; | |
// redirect to generated URL | |
apex.navigation.redirect(vUrl); |
Here is an example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vItemValue = 'New Item Value'; | |
// Example 1 - just get URL to go to the page 1 | |
vUrl = apex.util.makeApplicationUrl({pageId:1); | |
// Example 2 - go to page 1 and set value of item P1_ITEM | |
vUrl = apex.util.makeApplicationUrl({ | |
pageId:1, | |
itemNames:['P1_ITEM'], | |
itemValues:[vItemValue] | |
}); | |
// Example 3 - you can also set multiple items | |
var vItem2Value = 'New Item 2 Value'; | |
vUrl = apex.util.makeApplicationUrl({ | |
pageId:1, | |
itemNames:['P1_ITEM', 'P1_ITEM_2'], | |
itemValues:[vItemValue, vItem2Value] | |
}); | |
// Example 4 - all options | |
vUrl = apex.util.makeApplicationUrl({ | |
appId: 100, // default is $v("pFlowId") - current app | |
pageId:1, // default is $v("pFlowStepId") - current page | |
session: $v( "pInstance" ), // default is $v("pInstance") - current session | |
request: 'TEST_REQUEST', // default is $v("pRequest") - current request | |
debug: 'YES', // default is $v("pdebug") - debug YES/NO | |
itemNames:['P1_ITEM'], // item names array (no value by default) | |
itemValues:[vItemValue], // item values array (no value by default) | |
printerFriendly: 'YES' // no value by default | |
}); |
Enjoy!
Tested in APEX 19.1.0.00.15