Tuesday, 27 June 2017

Redirect On Page Load

Hi There,

You know that you can embed custom pages right inside Acumatica. Best examples here are YouTube, Binq, Stack Exchange, Currency Rates or something else

But what if you need something like this, but dynamic - have a special URL depend on user, screen or other environment variables. In that case you cannot just hard-code URL in sitemap, as it will be always the same.

Here we need to be able to redirect user to special URL form code.
And I can suggest you 2 possible options to do that:

When page is shown and graph is loaded, you can throw a redirect exception that will be handled by base code and user will be redirected.
Note that using WindowMode you can control should new URL be opened in new or same window.
However, here we have a small problem, empty screen will be shown for a second before redirect takes places. Somethings it might be not acceptable.

Redirect on PageLoad
Another way is to have a dummy page and register it in the sitemap. You can create dummy page with Customization Brower tools. Paige can be empty and does not require any business logic there.
As soon as page is loaded we can do a redirect.

In that approach you cannot use PXRedirectException, as there is no base code that can handle that, but we can use other ways to do redirect. And it should be different depend on requiest type: is current call Callback or GET/POST.
  • In case of callback we can provide special redirect instruction to response - eRedirect0 - that will be handled by Acumatica JavaScript on page
    • Number in redirect keyword means special configuration of redirect, for example redirects 0,1,5,6 will be in the same window; 3,4 in new tab; 7,8 in new window; Other numbers can suppress frame-set of keep session.
  • In case of GET/Post we can use JavaScript that will open a separate page
Here I have an example on how to do redirect to dynamic URL from PageLoad:
protected void Page_Load(object sender, EventArgs e)
       System.Web.HttpContext context = System.Web.HttpContext.Current;
       String url = "http://acumatica.com";

       Boolean iscallback = context.Request.Form["__CALLBACKID"] != null;
       Boolean isget = String.Equals(context.Request.HttpMethod, "GET",
       Boolean ispost = String.Equals(context.Request.HttpMethod, "POST",

       if (iscallback)
              context.Response.Write("eRedirect0:" + url);
       if (isget || ispost)
                     String.Format("window.open(\"{0}\",\"{1}\");", url, "main"));


If you add that code to your page code-behind, you will be able to see Acumatica page right when you click on the sitemap node.

Have a nice integration!

No comments: