formDataFieldStr for modified and formDatasourcestr for validateWrite and validateDelete method using chain of command
// formDataFieldStr
[ExtensionOf(formDataFieldStr(PurchTable, PurchLine, ItemId))]
final class BASSupplement_Extension
{
public void modified()
{
FormDataObject formDataObject = any2Object(this) as FormDataObject;
FormDataSource formDataSource = formDataObject.datasource();
PurchLine purchLine;
SuppItemTable supplementItem;
next modified();
purchLine = formDataSource.cursor();
while select * from supplementItem
where supplementItem.ItemRelation == purchLine.ItemId
{
PurchPurchaseOrderLineV2Entity purchLineEntity;
purchLineEntity.initValue();
purchLineEntity.PurchaseOrderNumber = purchLine.PurchId;
purchLineEntity.ItemNumber = supplementItem.SuppItemId;
purchLineEntity.insert();
purchLineEntity.clear();
}
//formDataSource.research();
//formDataSource.refresh();
}
}
// FormDataSourcestr
[ExtensionOf(FormDataSourcestr(PurchTable, PurchLine))]
final class BAS_SuppItem_Extension
{
// validateWrite
public boolean validateWrite()
{
boolean ret = next validateWrite();
FormDataSource formDataSource = this;
PurchLine purchLine = formDataSource.cursor();
SuppItemTable supplementItem;
select count(RecId) from supplementItem
where supplementItem.ItemRelation == purchLine.ItemId;
if(supplementItem.RecId != 0)
{
DialogButton dialogButton;
//Initial focus is on the No button.
dialogButton = Box::yesNo('Do you want to add supplementery items',dialogButton::Yes, "Proceed or Dont");
if(dialogButton == DialogButton::Yes)
{
PurchLine supplementLine;
while select SuppItemId from supplementItem
where supplementItem.ItemRelation == purchLine.ItemId
{
ttsbegin;
PurchTable purchTable = PurchTable::find(purchLine.PurchId);
supplementLine.initFromPurchTable(purchTable);
supplementLine.PurchId = purchLine.PurchId;
supplementLine.ItemId = supplementItem.SuppItemId;
// supplementLine.skipDataSourceValidateField(fieldNum(PurchLine,ItemId),true);
supplementLine.insert();
//supplementLine.createLine(true, true, true, true, true, false);
supplementLine.clear();
ttscommit;
}
//formDataSource.reread();
formDataSource.refresh();
// formDataSource.research();
info("Supplementery items have been added");
}
else if (dialogButton == DialogButton::No)
{
ret = checkFailed("Supplementery items must be added");
}
}
return ret;
}
}
Comments
Post a Comment