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

Axapta 如何通过代码设置InventLocation地址?,axapta,dynamics-ax-2012,x++,street-address,Axapta,Dynamics Ax 2012,X++,Street Address,我必须按代码设置地址。 通过代码,我知道如何找到InventLocation地址,但如果它不在那里,我想创建它 我的代码是: InventLocation invLocationTable; LogisticsPostalAddress logisticsPostalAddress; invLocationTable = InventLocation::find(MYinvLocationId); logisticsPostalAddress = LogisticsLocationEnt

我必须按代码设置地址。 通过代码,我知道如何找到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中引用,因此显然此表需要插入一条记录。下一个引用将在InventLocationLogisticsLocationRole.LocationLogisticsLocation中,您同样需要一个记录。最后是LogisticsPostalAddress.Location中的引用

因此,首先插入InventLocationLogisticsLocation,然后插入InventLocationLogisticsLocationRole,最后插入LogisticsPostLaddress

还要确保将角色类型定义为“无”,否则可能会丢失LocationPostLaddress中的记录