Page Refresh and Redirection

Hi All,

As you know Acumatica page submits all data to the server though different callbacks. This is good for network performance, but brings some limitations – like redirection. Unfortunately it is not possible to use Response.Redirect() during the callbacks as browser script does not expect it and can’t properly react.

To solve some of these issues Acumatica uses different exceptions (like PXRedirectRequiredException, PXReportRequiredException and so on). These Exceptions will be handled by base code (Callback Manager) and translated to text commands that will be handled in JavaScript.

For instance, PXRedirectRequiredException(WindowMode.New, SuppressFramceset = false) will be translated to eRedirect3:+<SomeURL>. You can read more about this mechanism here. This code is located in DataSource, so all requests comes from there, will be handled automatically.

Ok, what custom pages or services where we don’t have a PXDatasource? Lets assume we made some configuration changes and we need to refresh a UI to reflect these changes in the browser page. There is also an internal command that can be used – eRefresh.

public static void Refresh(string url)
	HttpContext context = HttpContext.Current;
	bool iscallback = !String.IsNullOrEmpty(context.Request.Form["__CALLBACKID"]);

	if (iscallback)
		context.Response.Redirect(url, false);

Please note that eRefresh can work only in scope of callback, as JavaScript in browser knows how to handle it. In case it is not a callback there is no script we need.
Also note that eRefresh should be the first line in response, so we clear the rest. Also i recommend to complete request as soon as possible, as there might be other code that modifies the response and it may interfere our message.

Also you can use eRefresh to open a new URL, like here:

public static void RefreshPage(System.Web.HttpContext context, string url)
	if (IsApi(context)) { return; }
		url = PX.Common.PXUrl.ToAbsoluteUrl(url);
	catch (ArgumentException) { /* SKIP */	}

	context.Response.Write("eRefresh|" + url + "|");

There are some helper methods that you can use in Acumatica Framework for specific redirection:

  • PX.Data.Redirector.Redirect(…) – User Response.Redirect approach
  • PX.Data.Redirector.RedirectPage(…) – Users redirect with JavaScript window.Open approach.
  • PX.Data.Redirector.Refresh(…) – Refresh page using eRefresh.
  • PX.Data.Redirector.RefreshPage(…) – Refresh page using eRefresh with URL as a parameter.
  • PX.Data.Redirector.SmartRedirect(…) – uses different ways to redirect based on the requests and context.

Hope it is helpful!

Leave a Reply

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