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:
PXRedirectToUrlException
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", StringComparison.InvariantCultureIgnoreCase); Boolean ispost = String.Equals(context.Request.HttpMethod, "POST", StringComparison.InvariantCultureIgnoreCase); context.Response.Clear(); if (iscallback) { context.Response.Write("eRedirect0:" + url); } else if (isget || ispost) { context.Response.Clear(); context.Response.Write("<script>"); context.Response.Write( String.Format("window.open("{0}","{1}");", url, "main")); context.Response.Write("</script>"); } context.Response.Cache.SetNoStore(); context.Response.Cache.SetNoServerCaching(); context.Response.End(); }
Testing
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!
Hi Sergey, thanks for this post and all of your other helpful post. I know this is an old post, but I’m trying to use this or any other technique to redirect to an external page through the GI navigation functionality..
I need to be able to pass parameters from the GI to my screen and use the parameter values to build a url that will be redirected to.
What would be the best approach to do this? I’m thinking I can just create a customization project with an empty page set that screen up on the navigation tab of my GI, but I’m not sure how to add the parameters.
Hi Scott in Acumatica 2021r1 you are able to use external link from GI directly. it is a standard functionality.
Hi Sergey,
Thanks for the info, in researching I had ran across that this was being added.
We are just about to upgrade to 2020 R2, so it will be some time before we can get to 2021 R1.
Any ideas how I can implement this in 2020 R1 and R2, I have an immediate need for the functionality? I tried creating a custom screen with a dummy data class. I can see my screen in my GI and I have the navigation setup, but when I try to navigate to the custom screen I get this error “Cannot open this record for editing: The form AH100001 does not contain it.” I assume this is because I’m not actually retrieving a data record. I’m not sure if there some way to get around and where I would need to put the redirect.
HI Scott,
I think you are right. You may need more than just a dummy screen. You need either the screen that will select the same DAC as you are using for navigation, or you need a screen with Filter view where you will pass the parameters using GI Designer.
Any way, it will be quite some additional development. I’m really sorry, I do not have a ready project for the demonstaration.
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.
Hi Arthur,
Page_Load is an event of ASP.Net page life-cycle. You can read more about it there:
https://www.c-sharpcorner.com/UploadFile/8911c4/page-life-cycle-with-examples-in-Asp-Net/
So this is not related to Acumatica events, and you have to edit ASPX.CS file (code behind file) manually. Use any editor you want, but it can’t be done from the browser, you need to edit it locally than add to customization project.
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.
Hi Kevin,
Please check this article https://asiablog.acumatica.com/2017/08/redirecting-to-external-page-from-button.html
and try other redirects like:
Redirect0 – open page in the same iFrame with no keeping session
Redirect1 – same as above but with keeping session
Redirect5, Redirect6 – same as above but with new popup
Redirect3 – will open new frame-set
Redirect7, Redirect8 – will open a new window
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”);
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.
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
toonsix@intercs.com