更新自定义字段将陷入无限循环 [英] Updating custom field is ending into infinite loop

查看:47
本文介绍了更新自定义字段将陷入无限循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在AR发票和备忘录中有一个自定义字段(屏幕ID AR301000),用于对应的AP参考。 Nbr。并且在类似的经理中,AP帐单和调整中的另一个自定义字段(屏幕ID AP301000)用于相应的AR Ref。 Nbr。

I have a custom field in AR Invoice and Memos (Screen ID AR301000) for the corresponding AP Ref. Nbr. And in the similar manager another custom field in AP Bills and Adjustment (Screen ID AP301000) for the corresponding AR Ref. Nbr.

我正在尝试更新AP参考。 Nbr。当用户更新AR参考时,在AR屏幕上显示。 Nbr。在AP屏幕中。

I am trying to update AP Ref. Nbr. on AR screen when user updates the AR Ref. Nbr. in AP screen.

例如-

我在AR屏幕发票0001上,我正在更新AP参考。 Nbr。到abc01。系统将使用相应的AR Ref自动更新AP Bill abc01。 Nbr。用0001。

I am on AR Screen Invoice 0001, I am updating AP Ref. Nbr. to abc01. System will automatically update the AP Bill abc01 with the corresponding AR Ref. Nbr. with 0001.

我已经编写了以下代码来实现此目的,但由于它们都试图更新其他屏幕中的相应字段,因此它陷入了无限循环。让我知道我是否遗漏了什么或者有更好的方法。

I have below code written to achieve this but it runs into infinite loop as both it is trying to update the corresponding fields in other screen. Let me know if I missing anything or there is a better way.

在AR图扩展上

public class ARInvoiceEntryExtension : PXGraphExtension<ARInvoiceEntry>
{
	protected virtual void ARInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
	{
		var row = (ARInvoice)e.Row;
		if (row != null && sender.IsDirty)
		{
			ARRegisterExtension ext = PXCache<ARRegister>.GetExtension<ARRegisterExtension>(row);

			if (ext != null && !string.IsNullOrEmpty(ext.UsrAPRefNbr))
			{
				APInvoiceEntry graph = PXGraph.CreateInstance<APInvoiceEntry>();

				APInvoice apRow = PXSelect<APInvoice,
					Where<APInvoice.refNbr, Equal<Required<APInvoice.refNbr>>>>.Select(graph, ext.UsrAPRefNbr);

				if (apRow != null)
				{
					APRegisterExtension ext1 = PXCache<APRegister>.GetExtension<APRegisterExtension>(apRow);
					if (ext1 != null && string.IsNullOrEmpty(ext1.UsrARRefNbr))        //Update only if it is empty
					{
						ext1.UsrARRefNbr = row.RefNbr;

						graph.Document.Current = apRow;

						graph.Caches[typeof(APRegister)].SetValue<APRegisterExtension.usrARRefNbr>(apRow, row.RefNbr);
						graph.Caches[typeof(APRegister)].Update(apRow);
						graph.Actions.PressSave();
					}
				}
			}
		}
	}
}

在AP图扩展上

public class APInvoiceEntryExtension : PXGraphExtension<APInvoiceEntry>
{
	protected virtual void APInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e)
	{
		var row = (APInvoice)e.Row;
		if (row != null && sender.IsDirty)
		{
			APRegisterExtension ext = PXCache<APRegister>.GetExtension<APRegisterExtension>(row);

			if (ext != null && !string.IsNullOrEmpty(ext.UsrARRefNbr))
			{
				ARInvoiceEntry graph = PXGraph.CreateInstance<ARInvoiceEntry>();

				ARInvoice arRow = PXSelect<ARInvoice,
					Where<ARInvoice.refNbr, Equal<Required<ARInvoice.refNbr>>>>.Select(graph, ext.UsrARRefNbr);

				if (arRow != null)
				{
					ARRegisterExtension ext1 = PXCache<ARRegister>.GetExtension<ARRegisterExtension>(arRow);
					if (ext1 != null && string.IsNullOrEmpty(ext1.UsrAPRefNbr))        //Update only if it is empty
					{
						ext1.UsrAPRefNbr = row.RefNbr;

						graph.Document.Current = arRow;

						graph.Caches[typeof(ARRegister)].SetValue<ARRegisterExtension.usrAPRefNbr>(arRow, row.RefNbr);
						graph.Caches[typeof(ARRegister)].Update(arRow);
						graph.Actions.PressSave();
					}
				}
			}
		}
	}
}

AR缓存扩展

public class ARRegisterExtension : PXCacheExtension<ARRegister>
{
	public abstract class usrAPRefNbr : PX.Data.IBqlField
	{
	}

	protected string _usrAPRefNbr;

	[PXDBString(15)]
	[PXUIField(DisplayName = "AP Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]

	[APInvoiceType.RefNbr(typeof(Search3<PX.Objects.AP.Standalone.APRegisterAlias.refNbr,
	InnerJoinSingleTable<APInvoice, On<APInvoice.docType, Equal<PX.Objects.AP.Standalone.APRegisterAlias.docType>,
		And<APInvoice.refNbr, Equal<PX.Objects.AP.Standalone.APRegisterAlias.refNbr>>>,
	InnerJoinSingleTable<Vendor, On<PX.Objects.AP.Standalone.APRegisterAlias.vendorID, Equal<Vendor.bAccountID>>>>,
	OrderBy<Desc<APRegister.refNbr>>>))]
	public virtual string UsrAPRefNbr
	{
		get; set;
	}
}

AP缓存扩展

public class APRegisterExtension : PXCacheExtension<APRegister>
{
	public abstract class usrARRefNbr : PX.Data.IBqlField
	{
	}

	protected string _usrARRefNbr;

	[PXDBString(15)]
	[PXUIField(DisplayName = "AR Ref Nbr.", Visibility = PXUIVisibility.SelectorVisible)]

	[ARInvoiceType.RefNbr(typeof(Search3<PX.Objects.AR.Standalone.ARRegisterAlias.refNbr,
	InnerJoinSingleTable<ARInvoice, On<ARInvoice.docType, Equal<PX.Objects.AR.Standalone.ARRegisterAlias.docType>,
		And<ARInvoice.refNbr, Equal<PX.Objects.AR.Standalone.ARRegisterAlias.refNbr>>>,
	InnerJoinSingleTable<Customer, On<PX.Objects.AR.Standalone.ARRegisterAlias.customerID, Equal<Customer.bAccountID>>>>,
	OrderBy<Desc<ARRegister.refNbr>>>))]
	public virtual string UsrARRefNbr
	{
		get; set;
	}
}

推荐答案

何时保存时,APInvoice_RowUpdated修改ARInvoice,ARInvoice依次修改APInvoice,后者触发APInvoice_RowUpdated产生事件调用的无限循环。 ARInvoice_RowUpdated中的反函数会更新APInvoice,这将导致类似的无限循环。

When saving, APInvoice_RowUpdated modifies ARInvoice which in turn modifies APInvoice which triggers APInvoice_RowUpdated producing an infinite loop of event calls. The inverse in ARInvoice_RowUpdated which updates APInvoice will result in a similar infinite loop.

要摆脱这种情况,您可以在实例化图形后的运行时删除图形事件处理程序。首先将您的事件处理程序访问修饰符公开,以便您可以引用它们:

To get out of this, you can remove the graph event handler at runtime after instantiating the graph. First make your event handler access modifier public so you can reference them:

public virtual void APInvoice_RowUpdated(PXCache sender, PXRowUpdatedEventArgs e) 

创建图后,获取扩展名并删除导致无限循环的处理程序:

After creating a graph, get the extension and remove the handler that cause the infinite loop:

APInvoiceEntry graph = PXGraph.CreateInstance<APInvoiceEntry>();
APInvoiceEntryExtension graphExt = graph.GetExtension<APInvoiceEntryExtension>();
graphExt.RowUpdated.RemoveHandler<APInvoice>(graphExt.APInvoice_RowUpdated);

对ARInvoice必须进行相同的修改,因为无限循环从AP到AR都是双向的从AR到AP。

The same modification has to be done for ARInvoice because the infinite loop goes both way, from AP to AR and from AR to AP.

这篇关于更新自定义字段将陷入无限循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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