Skip to main content

Notifications

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 847
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 2,982 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 847 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 2,982 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,359 Super User 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,520 Super User 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 2,982 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
     
     
     
     

Helpful resources

Quick Links

Can you answer this forum question?

You could make someone's day!

Community Newsletter - May 2024

Kudos to our community stars!

Community Spotlight of the Month

Kudos to Mohamed Amine Mahmoudi!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 283,623 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 224,463 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,146

Featured topics

Product updates

Dynamics 365 release plans