每次使用此代码,我都会收到一条错误消息“您无法编辑表Purchtable中的记录”。我不能继续订购。我的任务是获取每个站点的默认地址。
[ExtensionOf(formdatasourcestr(PurchCreateOrder, PurchTable))]
final class PurchCreateOrderGetDefAdress_Extension
{
[FormDataFieldEventHandler(formDataFieldStr(PurchCreateOrder, PurchTable, OrderAccount), FormDataFieldEventType::Modified)]
public static void OrderAccount_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
Formdatasource purchtable_ds = sender.datasource();
PurchTable purchtable = purchtable_ds.cursor();
InventSite inv;
InventLocation invent;
str iid = UserInfoSz::findDefaultSite(curUserId()).InventSiteId;
purchtable.inventsiteid = iid;
purchTable.setAddressFromInventSiteId(iid);
select firstonly invent where invent.inventsiteid == iid && invent.WMSLocationIdDefaultReceipt == "recv";
if(invent.RecId !=0)
{
purchtable.inventlocationid = invent.InventLocationId;
}
else
{
select firstonly invent where invent.inventsiteid == iid;
purchtable.inventlocationid = invent.InventLocationId;
}
}
}
我认为方法purchTable.setAddressFromInventSiteId(iid);
会导致您遇到此问题。
尝试此代码:
[ExtensionOf(formdatasourcestr(PurchCreateOrder, PurchTable))]
final class PurchCreateOrderGetDefAdress_Extension
{
[FormDataFieldEventHandler(formDataFieldStr(PurchCreateOrder, PurchTable, OrderAccount), FormDataFieldEventType::Modified)]
public static void OrderAccount_OnModified(FormDataObject sender, FormDataFieldEventArgs e)
{
Formdatasource purchtable_ds = sender.datasource();
PurchTable purchtable = purchtable_ds.cursor();
InventSite inv;
InventLocation invent;
str iid = UserInfoSz::findDefaultSite(curUserId()).InventSiteId;
ttsbegin;
If(purchtable.recid)
{
purchtable.selectforupdate(true);
purchtable.inventsiteid = iid;
purchTable.setAddressFromInventSiteId(iid);
select firstonly invent where invent.inventsiteid == iid && invent.WMSLocationIdDefaultReceipt == "recv";
if(invent.RecId !=0)
{
purchtable.inventlocationid = invent.InventLocationId;
}
else
{
select firstonly invent where invent.inventsiteid == iid;
purchtable.inventlocationid = invent.InventLocationId;
}
}
ttscommit;
}
}