web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

how to get the original value after validating dataField?

(0) ShareShare
ReportReport
Posted on by 932

I want to add control when I modify the "Product lifecycle state" : 

pastedimage1683102335808v1.png

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 ,

pastedimage1683102616456v2.png

I have the same question (0)
  • Martin Dráb Profile Picture
    238,580 Most Valuable Professional on at

    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.

  • Suggested answer
    Mohit Rampal Profile Picture
    12,565 Moderator on at

    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

  • BASMA Profile Picture
    932 on at
    this instruction does not exist 
    inventTable.orig().ProductLifecycleStateId

    I use this code , but the field doesn't keep the original value
     case 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;

  • Martin Dráb Profile Picture
    238,580 Most Valuable Professional on at

    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).

  • BASMA Profile Picture
    932 on at

    how can I display the old value of field in form after validating?

  • Martin Dráb Profile Picture
    238,580 Most Valuable Professional on at

    "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".

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 679 Super User 2026 Season 1

#2
Abhilash Warrier Profile Picture

Abhilash Warrier 332 Super User 2026 Season 1

#3
Martin Dráb Profile Picture

Martin Dráb 238 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans