页面加载后,Acumatica ERP按条件重定向 [英] Acumatica ERP redirect by condition after the page has been loaded

查看:111
本文介绍了页面加载后,Acumatica ERP按条件重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

打开第一页时,在某些情况下是否可以从一个自定义页面重定向到另一个自定义页面?

Is there any way to redirect from one custom page to another in case of some conditions when the first page is opened?

我尝试使用 PXRedirectByScreenIDException 具有 RowSelected 事件,但未处理该异常且重定向不起作用。

I have tried using PXRedirectByScreenIDException with RowSelected events but the exception is not being handled and redirect is not working.

protected void PrimaryView_RowSelected(PXCache sender,PXRowSelectedEventArgs e)
{
     if(some_expression)
     {
          throw new PXRedirectByScreenIDException("II999999", PXBaseRedirectException.WindowMode.Base, true);
     }
}


推荐答案

很多Acumatica功能仅在狭窄范围内起作用。我注意到重定向异常 Action事件处理程序的上下文中执行时始终有效。大概在执行这些处理程序时,框架会将调用包装在一个catch块周围,该catch块专门捕获那些重定向异常类型并执行重定向。在其他情况下,它可能无法捕获此特定类型,并导致部分未处理的异常。

Many Acumatica features work only in a narrow range of context. I noticed that Redirection Exception always work when executed in the context of an Action Event Handler . Presumably when executing those handlers the framework wraps the call around a catch block that specifically catch those redirection exception types and execute the redirection. In other contexts it probably doesn't catch this specific type and that results in a partially unhandled exception.

所以我在页面加载时进行重定向的想法是抛出重定向异常在动作事件处理程序中。需要从UI上下文中调用该操作,但否则仍将无法处理该操作。因此,我将使用JavaScript在页面加载时从UI调用操作。

So my idea to redirect on page load is to throw the redirection exception inside an action event handler. The action need to be called from the UI context though otherwise it will still be unhandled. So I'll use JavaScript to call the action from UI on page load.

图形扩展在操作事件处理程序的上下文中引发重定向异常:

Graph extension that throws the redirection exception in the context of an action event handler:

public class SOOrderEntry_Extension : PXGraphExtension<SOOrderEntry>
{
  public PXAction<SOOrder> Redirect;

  [PXButton]
  public virtual IEnumerable redirect(PXAdapter adapter)
  {
      throw new PXRedirectByScreenIDException("SO302000", PXBaseRedirectException.WindowMode.Base, true);

      return adapter.Get();
  }
}

我使用了添加控件添加JavaScript控件。对于新页面(而不是自定义现有页面),通常使用编辑ASPX 来添加JavaScript更容易。 JavaScript函数调用图形扩展中的重定向动作事件处理程序。

I used Add Controls to add the JavaScript control. For new pages (not customizing existing pages) it's generally easier to use Edit ASPX to add the JavaScript. The JavaScript function calls the redirection action event handler in the graph extension.

function Redirect_Initialize() { px_alls["ds"].executeCallback("redirect"); }

最后一步是在页面加载时调用JavaScript方法。我使用 CommandPerformed 是因为我从经验中知道它将被可靠地调用。您可以尝试 Initialize 或其他类型的 Load 事件作为JavaScript入口点,但是我对此不太走运。

Last step is to call the JavaScript method when the page loads. I used CommandPerformed because I know from experience it will be reliably called. You could try Initialize or other types of Load events as the JavaScript entry point but I had less luck with those.

我测试了这个完整的解决方案,它确实在加载时重定向。当您的条件无法以重定向结束时,它可能执行过多的回调,因此您必须对此进行测试,并在必要时选择另一个入口点。

I tested this complete solution and it did redirect on load. Maybe it might perform too many callbacks when your condition will not end in a redirection, you'll have to test that and pick another entry point if necessary.

如果找不到合适的入口点,我将使用全局JavaScript变量作为标志,以便它仅调用一次图形操作事件处理程序。重复调用JavaScript函数的开销非常低,重复调用服务器(IIS / ASP.Net)会带来巨大的损失。

If no suitable entry point is found I would use a global JavaScript variable as a flag so that it calls the graph action event handler only once. Repeatedly calling a JavaScript function has very low overhead, repeatedly calling back the server (IIS/ASP.Net) carry a huge penalty.

这篇关于页面加载后,Acumatica ERP按条件重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆