如何通过代码设置InventLocation地址?

How to set InventLocation address by code?

我必须通过代码设置 InventLocation Address。 通过代码我知道如何找到 InventLocation 地址,但如果不存在我想创建它。

我的代码是这样的:

InventLocation   invLocationTable;
LogisticsPostalAddress logisticsPostalAddress;

invLocationTable  = InventLocation::find(MYinvLocationId);
logisticsPostalAddress = LogisticsLocationEntity::findPostalAddress(invLocationTable, LogisticsLocationRoleType::None);

if (!logisticsPostalAddress )
{
 // Here I want to create/set the InventLocation adress, but I don't know how to do it.
}

可以制作吗?

您的 InventLocation.RecId 需要在 InventLocationLogisticsLocation.Location 中引用,所以显然这个 table 需要插入一条记录。下一个参考将在 InventLocationLogisticsLocationRole.LocationLogisticsLocation 中,您同样需要一个记录。最后,参考LogisticsPostalAddress.Location.

所以首先插入 InventLocationLogisticsLocation,然后插入 InventLocationLogisticsLocationRole,最后插入 LogisticsPostalAddress。

还要确保您的角色类型定义为 None,否则您可能会丢失 LocationPostalAddress 中的记录。