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

custom pages acumatica

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 = "";

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

       if (iscallback)
              context.Response.Write("eRedirect0:" + url);
       else if (isget || ispost)
                     String.Format(""{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.

custom pages acumatica

Have a nice integration!

7 Replies to “Redirect On Page Load”

  1. I would really like to use this, but I am unsure where in the customization project to put the page load event. Can you please provide instruction as to how to add the page_load event into an Acumatica customization project? Thanks.

  2. Thanks for the post, can i use this approach to redirect to another sitemap page, because if i use redirect0 it nested the whole site in the main area, not just the page, also the master page.

  3. Sergey,

    I have used below code but it is not reflecting me to the URL. Can you tell me why?
    throw new PXRedirectToUrlException(string.Format(“~/Frames/GetFile.ashx?fileID={0}”, (object)file), “Export Batch File”);

    1. Hi Prathyusha,
      Could you please give me the whole code snippet. I need to understand where you throw this exception.
      Please post it here or contact me by skype or email.

  4. Sergey:

    Thanks for this blog post. I will use it in our internal Acumatica customer portal.
    When our customer signs in to our Acumatica customer portal, we want to embed some SharePoint online sites that are relevant for that signed in customer/user.
    Of course we will offer the same capability to our Acumatica customers who subscribe to Acumatica.
    Great job.

    Toon Six

Leave a Reply

Your email address will not be published. Required fields are marked *