I want to add control when I modify the "Product lifecycle state" :
I add on validating eventHandler on dataField in dataSource :
[FormDataFieldEventHandler(formDataFieldStr(EcoResProductDetailsExtended, InventTable, ProductLifecycleStateId), FormDataFieldEventType::Validating)] public static void ProductLifecycleStateId_OnValidating(FormDataObject sender, FormDataFieldEventArgs e) { var args = e as FormDataFieldCancelEventArgs; SysTableIdView tableId; EcoResProductCategory productCategory; PdsApprovedVendorList approvedVendorList; FormDataSource InventTable_ds = sender.datasource(); InventTable inventTable = InventTable_ds.cursor(); EcoResProductLifecycleState productLifeCycleState = EcoResProductLifecycleState::find(inventTable.ProductLifecycleStateId); CorollaryTable corollaryTable ; boolean ret; while select * from corollaryTable where corollaryTable.StateId == productLifeCycleState.StateId { if(corollaryTable) { select Name from tableId where tableId.Id == corollaryTable.TableNum; switch (tableId.Name) { case "EcoResProductCategory" : select Product from productCategory where productCategory.Product == InventTable.Product; if(!productCategory) { ret = checkFailed("La table " corollaryTable.TableLabel " n'est pas renseignée !"); args.cancel(true); } break; case "PdsApprovedVendorList" : select ItemId from approvedVendorList where approvedVendorList.ItemId == InventTable.ItemId; if(!approvedVendorList) { ret = checkFailed("La table " corollaryTable.TableLabel " n'est pas renseignée !"); args.cancel(true); } break; } } } }I get the new selected value ,
but I want to keep the old value of this field ,
"how to get the original value after validating dataField" is easy - the table buffer contains the value.
But your actual request seems to be changing the form control value during validation and I didn't succeed with it either. If I update the table field, it's just displayed in "Last valid value".
how can I display the old value of field in form after validating?
Trying to save the record is a bug. Here we're talking about changing a field value; the record wasn't saved. Your goal is just changing the field value, not to saving the record (which may even be impossible to save).
this instruction does not existinventTable.orig().ProductLifecycleStateId
I use this code , but the field doesn't keep the original valuecase tableNum(PdsApprovedVendorList): PdsApprovedVendorList approvedVendorList; select firstOnly RecId from approvedVendorList where approvedVendorList.ItemId == inventTable.ItemId; if (!approvedVendorList) { ttsbegin; inventTable_orig = inventTable.orig(); inventTable.ProductLifecycleStateId = inventTable_orig.ProductLifecycleStateId; inventTable.update(); ttscommit; warning(strFmt("La table %1 n'est pas renseignée ", corollaryTable.TableLabel)); args.cancel(true); } break;
Hi, You need to return false in ValidateField method. Can you try returning false in the parmValidateResults. Check this thread.
community.dynamics.com/.../onvalidating-for-form-control-event-handler-in-d365
Let me simplify your code, so it's easier to work with:
[FormDataFieldEventHandler(formDataFieldStr(EcoResProductDetailsExtended, InventTable, ProductLifecycleStateId), FormDataFieldEventType::Validating)] public static void ProductLifecycleStateId_OnValidating(FormDataObject sender, FormDataFieldEventArgs e) { FormDataFieldCancelEventArgs args = e as FormDataFieldCancelEventArgs; FormDataSource inventTable_ds = sender.datasource(); InventTable inventTable = inventTable_ds.cursor(); EcoResProductLifecycleState productLifeCycleState = EcoResProductLifecycleState::find(inventTable.ProductLifecycleStateId); CorollaryTable corollaryTable; while select corollaryTable where corollaryTable.StateId == productLifeCycleState.StateId { switch (corollaryTable.TableNum) { case tableNum(EcoResProductCategory): EcoResProductCategory productCategory; select firstOnly RecId from productCategory where productCategory.Product == inventTable.Product; if (!productCategory) { warning(strFmt("La table %1 n'est pas renseignée ", corollaryTable.TableLabel)); args.cancel(true); } break; case tableNum(PdsApprovedVendorList): PdsApprovedVendorList approvedVendorList; select firstOnly RecId from approvedVendorList where approvedVendorList.ItemId == inventTable.ItemId; if (!approvedVendorList) { warning(strFmt("La table %1 n'est pas renseignée ", corollaryTable.TableLabel)); args.cancel(true); } break; } } }
I guess that you're looking for inventTable.orig().ProductLifecycleStateId.
André Arnaud de Cal...
291,996
Super User 2025 Season 1
Martin Dráb
230,853
Most Valuable Professional
nmaenpaa
101,156