Hi all. I am using APEX 23.1.
I have a button that should be displayed on approximately every page in the application. The button should show a confirm message when clicked. The confirm message has two buttons. One of them should check for a condition, and if true it will redirect to page(5). The other button should always redirect to page 5.
Page 5 has “Page Access Protection” set to “Arguments must have checksum”.
Here's the javaScript code that I need to run when the button is clicked…
apex.message.confirm('myMsg',
function(addProvider){
if (addProvider){
console.log('add provider button clicked');
apex.navigation.redirect('f?p=&APP_ID.:5:&APP_SESSION.:ADD');
} else {
if ($v("pFlowStepId") !== "1"){
console.log('Search button clicked');
apex.navigation.redirect('f?p=&APP_ID.:1:&APP_SESSION.');
}
}
},
{
confirmLabel: "Add Provider",
cancelLabel: "Search"
}
)
I developed a solution and it worked but I am not sure if it's the best way to solve this problem.
I created the button in page 0, and created p0_url_to_call hidden page item.
The button has one “Execute server-side code” dynamic action that constitutes the url on the server using apex_page.get_url and assign the returned value to p0_url_to_call item. “items to return” is set to "p0_url_to_call" and “Wait for result” is set to "Yes".
Then the javaScript code above is put in a subsequent true action.
Problems about that solution:
1- I'll have the page item rendered in every page in the app.
2- when p0_url_to_call is returned and redirecting starts, it page shows a message to user asking if he really want to leave the page. That's because the item's value changed from null to a non null value. And of course, I do not want this message to be displayed.
I'd appreciate if there's a better solution.