Skip to main content

Notifications

Finance | Project Operations, Human Resources, ...
Suggested answer

how to get the original value after validating dataField?

(0) ShareShare
ReportReport
Posted on by 920

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: how to get the original value after validating dataField?

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

  • BASMA Profile Picture
    BASMA 920 on at
    RE: how to get the original value after validating dataField?

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

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: how to get the original value after validating dataField?

    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
    BASMA 920 on at
    RE: how to get the original value after validating dataField?
    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;

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: how to get the original value after validating dataField?

    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

  • Martin Dráb Profile Picture
    Martin Dráb 230,853 Most Valuable Professional on at
    RE: how to get the original value after validating dataField?

    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.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,996 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans