Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / OnModifiedFieldValue()...
Finance forum
Suggested answer

OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?

Posted on by 855
Hi awesome community!
 
I'm trying to write a code that should run once a status field value has changed.
 
The table that has the status field is in Model1, and I want to write my code in a different model Model2.
 
And what I want to accomplish is when the status field will change to a different value for a record in a table in Model1, I want my code in Model2 to run.
 
I tried using /Events/ available in the table and copied the event handler and pasted it in a class in Model2.
 
The events I tried:
- OnModifiedField
- OnModifiedFieldValue
Screenshot for events in table:
 
But both of these events did not trigger when I changed the value in the Table in model1.
 
Note*: The status field value is changing through a workflow. So once I click on the workflow Approve button on the form for the workflow, the status field value will change once workflow is complete.
 
Why the events are not triggering? is it because I'm modifying the field through workflow?
 
How to achieve once the status field changed in the table in model1, the code in model2 should run?
 
Any advice is appreciated !
 
Thanks in advance!
  • Waed Ayyad Profile Picture
    Waed Ayyad 5,451 Super User 2024 Season 2 on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    Hi,
     
    Is your issue resolved?  If yes, mark the answers that helped you as verified.

    Thanks,
    Waed Ayyad
  • Waed Ayyad Profile Picture
    Waed Ayyad 5,451 Super User 2024 Season 2 on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    Hi,
     
    1- Do you mean that you added the COC, and no change has happened?
     
    2- Did you try to debug the code? If no, try to debug it and see if the code is being hit when you try to complete it (You should attach Batch process when you debug the code.
     
    3- Can you share more details/ code in order to help you?
     
     
    Thanks
    Waed Ayyad
     
     
     
     
     
  • Momochi Profile Picture
    Momochi 855 on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
     
    It's really strange that when I try to do a CoC for the workflow classes, the CoC class won't trigger.
    I even tried to CoC the table update method table.update(), and also, it did not trigger.
     
    I'm actually totally unable to CoC the update happening through the workflow.
     
    The workflow is in model 1 and I'm trying to CoC through model 2 that is referencing model 1.
  • Waed Ayyad Profile Picture
    Waed Ayyad 5,451 Super User 2024 Season 2 on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    Hi,

    Is your issue resolved? If yes, mark the answers that helped you as verified.


    Thanks
    Waed Ayyad
  • Suggested answer
    Komi Siabi Profile Picture
    Komi Siabi 12,600 Most Valuable Professional on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    Like Waed said, the best place to put your logic is in the complete method in the workflow TypeEventHandler class.
  • Suggested answer
    Bharani Preetham Peraka Profile Picture
    Bharani Preetham Pe... 3,572 Moderator on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    The events will trigger if the method is triggered. The methods like modified or validateField will only trigger if you are calling them explicitly if you want them from code. When you change any value in a form then these will trigger from standard. So when you are changing this value you just need to write code like below.
     
    tableName.modifiedField(fieldNum(TableName, FieldName));
  • Suggested answer
    Waed Ayyad Profile Picture
    Waed Ayyad 5,451 Super User 2024 Season 2 on at
    OnModifiedFieldValue() Event Handler Not Getting Triggered, Am I Doing It Right?
    Hi,
     
    You should create an extension of the workflow class methods like (completed) method and add your code there.
    Note in case you are working on custom workflow then you can add your code to workflow complete method directly.

    [ExtensionOf(classStr(YourWorkflowTypeEventHandler))]
    final class YourWorkflowTypeEventHandler_Extension
    {
        public void completed(WorkflowEventArgs _workflowEventArgs)
        {
             //Add your logic to update status
            // Call the standard method
            next completed(_workflowEventArgs);
    
            }
        }
    }


     
    Thanks,
    Waed Ayyad
    If this helped, please mark it as "Verified" for others facing the same issue
     
     
     
     

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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

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

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,524 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,493 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans