acumatica c# / 添加 SOPackageDetailEx
acumatica c# / Add SOPackageDetailEx
我尝试添加一行包时出现此错误
错误:另一个进程添加了“SOPackagedetail”记录。您的更改将会丢失。
error
My c# code is this :
protected virtual void creationColis()
{
SOShipment ship=Base.CurrentDocument.Select();
SOPackageDetailEx colis = new SOPackageDetailEx();
colis.BoxID="COLIS";
colis.PackageType="M";
colis.ShipmentNbr=ship.ShipmentNbr;
SOShipmentEntry graph = PXGraph.CreateInstance<SOShipmentEntry>();
graph.Packages.Insert(colis); //insertion de l'enregistrement
graph.Packages.Update(colis);
graph.Actions.PressSave();
graph.Clear();
}
你知道我必须改变什么吗?
非常感谢
泽维尔
您的问题需要更多背景信息。对于初学者,您的代码位于何处?鉴于您引用了 Base.CurrentDocument.Select,我假设您正在扩展 SOShipmentEntry 以添加您的代码。
在这种情况下,您只需使用 Base.Packages 视图,而不是初始化您自己的 SOShipmentEntry 实例,您的示例将在其中尝试使用 graph.Packages。无论如何,这里有 2 个部分需要解决。
Packages 不是 SOShipmentEntry 的主要视图。创建图的实例时,必须告诉图在主视图中需要什么记录。在您创建图形的新实例的示例中,您可以执行如下操作:
graph.Document.Current = graph.Document.Search(myShipmentNbr);
如果您正在处理 SOShipmentEntry 的图形扩展,那么您可能不需要创建图形的新实例。在添加包裹记录之前,请确保 graph.Document.Current 不为空 - 请参阅项目符号 2。
- 选择货件后,您可以插入包裹信息。但是,您在这里有效地完成此操作的方式是尝试将随机包裹添加到空货件(通过视图的结构),但通过纯粹的蛮力强制记录附加到正确的货件。视图不喜欢那样工作。
在您有当前货件(文档)后添加包裹的更好方法如下:
// Find the current shipment (from the primary view Document)
SOShipment ship = Base.Document.Current();
if(ship?.ShipmentNbr != null) {
// Insert a record into the Packages view of the current shipment and return the record into colis
SOPackageDetailEx colis = Base.Packages.Insert(colis);
// Set the custom values
colis.BoxID="COLIS";
colis.PackageType="M";
// Update the Packages cache with the modified fields
Base.Packages.Update(colis);
// If more fields need to be updated after those changes were applied, instead do this...
colis = Base.Packages.Update(colis);
colis.FieldA = ValueA;
colis.FieldB = ValueB;
Base.Packages.Update(colis);
// If a save is needed, now is the time
Base.Save.Press();
}
请注意,我没有指定 ShipmentNbr。这是因为 DAC 定义了该字段以通过这 2 个属性从 SOShipment 中提取 ShipmentNbr。
[PXParent(typeof(FK.Shipment))]
[PXDBDefault(typeof(SOShipment.shipmentNbr))]
这意味着在创建记录时,Acumatica 应该通过 Key 查找父 SOShipment 记录,并在该字段上执行 DBDefault 以将其分配给 SOShipment.ShipmentNbr 值(来自父项)。重要附注:PXDefault 和 PXDBDefault 不可互换。我们经常使用 PXDefault,但在我的脑海中,除了像这种特定用法这样的数据库值默认值之外,我想不出 PXDBDefault 的情况。
我尝试添加一行包时出现此错误 错误:另一个进程添加了“SOPackagedetail”记录。您的更改将会丢失。
error
My c# code is this :
protected virtual void creationColis()
{
SOShipment ship=Base.CurrentDocument.Select();
SOPackageDetailEx colis = new SOPackageDetailEx();
colis.BoxID="COLIS";
colis.PackageType="M";
colis.ShipmentNbr=ship.ShipmentNbr;
SOShipmentEntry graph = PXGraph.CreateInstance<SOShipmentEntry>();
graph.Packages.Insert(colis); //insertion de l'enregistrement
graph.Packages.Update(colis);
graph.Actions.PressSave();
graph.Clear();
}
你知道我必须改变什么吗? 非常感谢 泽维尔
您的问题需要更多背景信息。对于初学者,您的代码位于何处?鉴于您引用了 Base.CurrentDocument.Select,我假设您正在扩展 SOShipmentEntry 以添加您的代码。
在这种情况下,您只需使用 Base.Packages 视图,而不是初始化您自己的 SOShipmentEntry 实例,您的示例将在其中尝试使用 graph.Packages。无论如何,这里有 2 个部分需要解决。
Packages 不是 SOShipmentEntry 的主要视图。创建图的实例时,必须告诉图在主视图中需要什么记录。在您创建图形的新实例的示例中,您可以执行如下操作:
graph.Document.Current = graph.Document.Search
(myShipmentNbr);
如果您正在处理 SOShipmentEntry 的图形扩展,那么您可能不需要创建图形的新实例。在添加包裹记录之前,请确保 graph.Document.Current 不为空 - 请参阅项目符号 2。
- 选择货件后,您可以插入包裹信息。但是,您在这里有效地完成此操作的方式是尝试将随机包裹添加到空货件(通过视图的结构),但通过纯粹的蛮力强制记录附加到正确的货件。视图不喜欢那样工作。
在您有当前货件(文档)后添加包裹的更好方法如下:
// Find the current shipment (from the primary view Document)
SOShipment ship = Base.Document.Current();
if(ship?.ShipmentNbr != null) {
// Insert a record into the Packages view of the current shipment and return the record into colis
SOPackageDetailEx colis = Base.Packages.Insert(colis);
// Set the custom values
colis.BoxID="COLIS";
colis.PackageType="M";
// Update the Packages cache with the modified fields
Base.Packages.Update(colis);
// If more fields need to be updated after those changes were applied, instead do this...
colis = Base.Packages.Update(colis);
colis.FieldA = ValueA;
colis.FieldB = ValueB;
Base.Packages.Update(colis);
// If a save is needed, now is the time
Base.Save.Press();
}
请注意,我没有指定 ShipmentNbr。这是因为 DAC 定义了该字段以通过这 2 个属性从 SOShipment 中提取 ShipmentNbr。
[PXParent(typeof(FK.Shipment))]
[PXDBDefault(typeof(SOShipment.shipmentNbr))]
这意味着在创建记录时,Acumatica 应该通过 Key 查找父 SOShipment 记录,并在该字段上执行 DBDefault 以将其分配给 SOShipment.ShipmentNbr 值(来自父项)。重要附注:PXDefault 和 PXDBDefault 不可互换。我们经常使用 PXDefault,但在我的脑海中,除了像这种特定用法这样的数据库值默认值之外,我想不出 PXDBDefault 的情况。