Acumatica 为客户位置构建处理屏幕
我需要为客户位置构建一个处理屏幕,确定并更新位置上的居住标志 此代码正确处理每个选定记录,并显示为更新相应字段。但我遇到的问题是,我对Acumatica 为客户位置构建处理屏幕,acumatica,Acumatica,我需要为客户位置构建一个处理屏幕,确定并更新位置上的居住标志 此代码正确处理每个选定记录,并显示为更新相应字段。但我遇到的问题是,我对位置的更改没有保存回数据库 客户位置图要求在输入位置ID之前指定业务帐户,因此我怀疑我无法简单地更新图上的位置视图。但我找不到任何文档或代码示例来说明我应该在这里使用什么方法 以下是我的处理屏幕图上的代码: public class ProcessCustomerLocations : PXGraph<ProcessCustomerLocations>
位置的更改没有保存回数据库
客户位置图要求在输入位置ID之前指定业务帐户,因此我怀疑我无法简单地更新图上的位置视图。但我找不到任何文档或代码示例来说明我应该在这里使用什么方法
以下是我的处理屏幕图上的代码:
public class ProcessCustomerLocations : PXGraph<ProcessCustomerLocations>
{
public PXCancel<Location> Cancel;
public PXProcessing<Location, Where<Location.isActive, Equal<True>>> Locations;
public static void Process(List<Location> locations)
{
var graph = PXGraph.CreateInstance<CustomerLocationMaint>();
CustomerLocationMaint_Extension graphExt = graph.GetExtension<CustomerLocationMaint_Extension>();
foreach (var location in locations)
{
graphExt.UpdateLocation(location, true);
}
}
public ProcessCustomerLocations()
{
Locations.SetProcessDelegate(Process);
}
}
更新
感谢@Samvel的帮助,我修改了UpdateLocation
代码如下。下面的代码确实保存了对数据库的更改(包括自定义字段和非自定义字段),这非常好。然而,为了做到这一点,我必须创建一个新的位置对象“myLocation”,并且不再使用PXProcessing图形传递给UpdateLocation的“Location”对象。这意味着在处理之后,当处理屏幕显示带有修改数据的已处理记录时(在处理完成之后和刷新屏幕之前),它不会显示更新的值。有没有办法让处理屏幕显示更新的值并将更改保存到数据库
public void UpdateLocation(PX.Objects.CR.Location location, bool isMassProcess = false)
{
bool isRes = true;
Location myLocation = PXSelect<Location,
Where<Location.bAccountID, Equal<Required<Location.bAccountID>>, And<Location.locationID, Equal<Required<Location.locationID>>>>>
.Select(this.Base, location.BAccountID, location.LocationID);
this.Base.Location.Current = myLocation;
LocationExt locationExt = myLocation.GetExtension<LocationExt>();
locationExt.UsrResidentialValidated = true;
myLocation.CResedential = isRes;
Base.Location.Current = Base.Location.Update(myLocation);
this.Base.Save.Press();
}
public void UpdateLocation(PX.Objects.CR.Location,bool isMassProcess=false)
{
bool-isRes=true;
位置myLocation=PXSelect
.选择(this.Base,location.BAccountID,location.LocationID);
this.Base.Location.Current=myLocation;
LocationExt LocationExt=myLocation.GetExtension();
locationExt.UsrResidentialValidated=true;
myLocation.CResedential=isRes;
Base.Location.Current=Base.Location.Update(myLocation);
this.Base.Save.Press();
}
已更新
我已经根据你的情况更新了代码。处理完所有记录后,网格中的记录将被更新,并显示修改后的记录。
您可以通过以下方式下载此代码的自定义包:
要创建用于更新位置的处理页面,应执行以下步骤:
将“选定”字段添加到位置DAC
public sealed class LocationExt: PXCacheExtension<Location>
{
#region Selected
public abstract class selected : IBqlField
{ }
[PXBool()]
[PXDefault(true,PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Selected")]
public bool? Selected { get; set; }
#endregion
#region UsrResidentialValidated
[PXDBBool]
[PXUIField(DisplayName = "Residential Validated")]
public bool? UsrResidentialValidated { get; set; }
public abstract class usrResidentialValidated : IBqlField { }
#endregion
}
正如您所看到的,由于某种原因,我隐式地指定了PX.Objects.AR和PX.Objects.CR,程序在我的实例上仅以这种方式工作
在GraphExtension中创建UpdateLocation方法:
using PX.Data;
namespace CustomerLocationUpdate
{
public class CustomerLocationMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerLocationMaint>
{
public void UpdateLocation(PX.Objects.CR.Location location, bool isMassProcess = false)
{
bool isRes = false;
this.Base.Location.Current = PXSelect<PX.Objects.CR.Location,Where<PX.Objects.CR.Location.bAccountID,Equal<Required<PX.Objects.CR.Location.bAccountID>>,And<PX.Objects.CR.Location.locationID,Equal<Required<PX.Objects.CR.Location.locationID>>>>>.Select(this.Base,location.BAccountID,location.LocationID);
this.Base.Location.Current.CResedential = isRes;
LocationExt locationExt = PXCache<PX.Objects.CR.Location>.GetExtension<LocationExt>(this.Base.Location.Current);
locationExt.UsrResidentialValidated = false;
this.Base.Location.Current = this.Base.Location.Update(this.Base.Location.Current);
this.Base.Save.Press();
}
}
}
使用PX.Data;
命名空间CustomerLocationUpdate
{
公共类CustomerLocationMaint_扩展:PXGrapherExtension
{
public void UpdateLocation(PX.Objects.CR.Location,bool isMassProcess=false)
{
bool-isRes=false;
this.Base.Location.Current=PXSelect.Select(this.Base,Location.BAccountID,Location.LocationID);
this.Base.Location.Current.CResedential=isRes;
LocationExt LocationExt=PXCache.GetExtension(this.Base.Location.Current);
locationExt.UsrResidentialValidated=false;
this.Base.Location.Current=this.Base.Location.Update(this.Base.Location.Current);
this.Base.Save.Press();
}
}
}
如您所见,我正在使用PXSelect设置Location.Current
,而不是Location.Current.Search
。
由于某种原因,Location.Current.Search
总是返回null。
可能是应用于它的PXProjectionAttribute造成的,我不确定确切原因是什么
这对我来说只是部分起作用。您会注意到我需要更新两个字段:location.CResedential
和locationExt.UsrResidentialValidated
一个是自定义字段,另一个不是。使用这种方法,只有对CResidenial(非自定义字段)的更改被保存到数据库中,而对Usr字段的更改则不会被保存到数据库中。此外,在处理之后,处理屏幕显示已处理的记录以及更新的数据。该初始结果表明Usr字段已更新,而CResedential字段未更新,这与实际情况相反persisted@abulger您是否将自定义字段的更新添加到我的代码示例中?我没有编写准确的代码来工作,因为这是一个关于如何更新位置记录数据的初始示例。是的,我更新了代码以包括您提供的更改。您的更改允许我成功更改非自定义字段,但对自定义字段的更改仍然没有被持久化。@abulger您能将自定义字段的定义添加到问题中吗?是的,我能做到!我已将自定义字段代码添加到原始问题中。我还添加了更新版本的UpdateLocation
,它基于您的建议,但创建了一个新的位置对象。此版本成功保存对自定义字段和非自定义字段的更改。这就是进步!但是,由于我们不再处理从处理图传入的“位置”,因此处理结果中显示的数据(处理完成后但刷新屏幕之前)不会更新。有什么想法吗?
public sealed class LocationExt: PXCacheExtension<Location>
{
#region Selected
public abstract class selected : IBqlField
{ }
[PXBool()]
[PXDefault(true,PersistingCheck = PXPersistingCheck.Nothing)]
[PXUIField(DisplayName = "Selected")]
public bool? Selected { get; set; }
#endregion
#region UsrResidentialValidated
[PXDBBool]
[PXUIField(DisplayName = "Residential Validated")]
public bool? UsrResidentialValidated { get; set; }
public abstract class usrResidentialValidated : IBqlField { }
#endregion
}
using PX.Data;
using PX.Objects.CR;
using System.Collections.Generic;
namespace CustomerLocationUpdate
{
public class ProcessCustomerLocations : PXGraph<ProcessCustomerLocations>
{
public PXCancel<Location> Cancel;
public PXProcessingJoin<Location,InnerJoin<BAccountR,On<Location.bAccountID,Equal<BAccountR.bAccountID>>>,
Where<Location.isActive, Equal<True>,And<Location.locType, Equal<PX.Objects.CR.LocTypeList.customerLoc>>>> Locations;
public static void Process(List<Location> locations)
{
var graph = PXGraph.CreateInstance<PX.Objects.AR.CustomerLocationMaint>();
CustomerLocationMaint_Extension graphExt = graph.GetExtension<CustomerLocationMaint_Extension>();
foreach (var location in locations)
{
graphExt.UpdateLocation(location, true);
graph.Clear();
}
}
public ProcessCustomerLocations()
{
Locations.SetProcessDelegate(Process);
}
}
}
using PX.Data;
namespace CustomerLocationUpdate
{
public class CustomerLocationMaint_Extension : PXGraphExtension<PX.Objects.AR.CustomerLocationMaint>
{
public void UpdateLocation(PX.Objects.CR.Location location, bool isMassProcess = false)
{
bool isRes = false;
this.Base.Location.Current = PXSelect<PX.Objects.CR.Location,Where<PX.Objects.CR.Location.bAccountID,Equal<Required<PX.Objects.CR.Location.bAccountID>>,And<PX.Objects.CR.Location.locationID,Equal<Required<PX.Objects.CR.Location.locationID>>>>>.Select(this.Base,location.BAccountID,location.LocationID);
this.Base.Location.Current.CResedential = isRes;
LocationExt locationExt = PXCache<PX.Objects.CR.Location>.GetExtension<LocationExt>(this.Base.Location.Current);
locationExt.UsrResidentialValidated = false;
this.Base.Location.Current = this.Base.Location.Update(this.Base.Location.Current);
this.Base.Save.Press();
}
}
}