Hi there, as per the requirement we had added lookup method in InventTransferOrder Form for PurchId field. In the lookup method we have added range like PurchLine.PurchStatus != Cancelled. Now how to add an Validation like if user manually enters any other Purchid other than once coming from lookup method, we need ti throw error message and the record should not be saved. Now, the record is saving and we are looking how to add error message if user selects wrong PuchId. Please find my below code for lookup method and suggest me accordingly. Thanks in advance
public static void InventTransferLine_HAMPurchId_OnLookup(FormControl sender, FormControlEventArgs e)
{
Query query;
QueryBuildDataSource qbds;
SysTableLookup lookup;
QueryBuildRange queryBuildRange,queryBuildRange1;
FormRun formRun = sender.formRun() as FormRun;
FormDataSource inventTransferLine_ds = formRun.dataSource(formDataSourceStr(InventTransferOrders ,InventTransferLine)) as FormDataSource;
InventTransferLine deliveryModeService = inventTransferLine_ds.cursor();
// Create the query for the lookup
query = new query();
qbds = query.addDataSource( tableNum(PurchLine));
FormControlCancelableSuperEventArgs event = e as FormControlCancelableSuperEventArgs;
event.CancelSuperCall();
InventTransferLine inventTransferLine;
PurchLine purchLine;
// Instantiate sysTableLookup object using table which will provide the visible fields
lookup = SysTableLookup::newParameters( tableNum(PurchLine), sender);
// Add fields that will be shown in the lookup as columns
lookup.addLookupfield( fieldNum(PurchLine,PurchId));
lookup.addLookupMethod(tablemethodStr(PurchLine,getPurchName));
queryBuildRange = qbds.addRange(fieldnum(PurchLine,ItemId));
queryBuildRange.value(deliveryModeService.ItemId);
queryBuildRange1 = qbds.addRange(fieldnum(PurchLine, PurchStatus));
queryBuildRange1.value(SysQuery::valueNot(PurchStatus::Canceled));
// Add the query to the lookup form
lookup.parmQuery(query);
// Perform the lookup
lookup.performFormLookup();
}
// We need to add validation not to save record if PurchId is not as per Lookup and need to throw error message accordingly. Thanks