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

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

DataEventHandler On validate write

(0) ShareShare
ReportReport
Posted on by 87

I am trying to create a new validation on WMSBillOfLadingOrder.

I am trying to create a new validation on WMSBillOfLadingOrder.
I created field names grossWeight and tareWeight.
Validate is grossWeight greater Than tareWeight.

this is EventHandler

[DataEventHandler(tableStr(WMSBillOfLadingOrder), DataEventType::ValidatedWrite)]
public static void WMSBillOfLadingOrder_onValidatedWrite(Common sender, DataEventArgs e)
{       
}

I have the same question (0)
  • Sukrut Parab Profile Picture
    71,699 Moderator on at
    RE: DataEventHandler On validate write

    You forgot to explain about your issue . Anyways my guess is you don't know  get fields from sender , use below syntax to get the table and access its fields so that you can do comparison. 

    WMSBillOfLadingOrder WMSBillOfLadingOrder = sender as WMSBillOfLadingOrder;

    If your problem is something else , please explain. 

  • pavilionit Profile Picture
    87 on at
    RE: DataEventHandler On validate write

    The problem is that I want to check if the first value is greater than the second value, then I will subtract them from each other and then put the value in another place, and if the second value is greater than the first, he should tell me this

    I hope I have clarified the problem

  • André Arnaud de Calavon Profile Picture
    300,059 Super User 2025 Season 2 on at
    RE: DataEventHandler On validate write

    Hi pavilionit,

    You explained the business requirement. This is clear. Do you need help with the actual coding? If so, what part is unclear to you? Your method is empty, so I don't know what exact help you need.

    If you need to get the entered data in a table buffer, you can use the next line in your method:

    WMSBillOfLadingOrder wmsBillOfLadingOrder = sender;

    Note that you have two actions:

    - fill details in another field based on a calculation

    - validate dates; one should be greater than the other.

    For filling the calculation result in another field, you can better use other methods, like modifiedField or insert() and update().

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: DataEventHandler On validate write

    Hi paviollionit,

    you can also use Chain of Command instead of event handlers - the syntax is easier and generally it offers more possibilities. Please note that you should not change any data in validation methods as Andre pointed out. ValidateWrite should simply check if the current record is ok or not, it should not update anything in it.

  • pavilionit Profile Picture
    87 on at
    RE: DataEventHandler On validate write

    The problem is that I want to check if the first value is greater than the second value, then I will subtract them from each other and then put the value in another place, and if the second value is greater than the first, he should tell me this

    I hope I have clarified the problem

  • Suggested answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: DataEventHandler On validate write

    Hi,

    it seems that perhaps your code doesn't belong to validateWrite. ValidateWrite should have the final data and validate it. It should not change the data.

  • pavilionit Profile Picture
    87 on at
    RE: DataEventHandler On validate write

    this is code validate in entering values and calculate the weight.

    I need  to make code on DataEventHandle does the same thing

       public void modifiedField(FieldId _fieldId)

       {

           next modifiedField(_fieldId);

           switch (_fieldId)

           {

               case fieldNum(WMSBillOfLadingOrder, grossWeight):

               case fieldNum(WMSBillOfLadingOrder, tareWeight):

                   this.calculateWeight();

                   break;

           }

       }

       void calculateWeight()

       {

             this.validateWrite();

             this.weight = this.grossWeight - this.tareWeight;

       }

       boolean validateWrite()

       {

           boolean ret= next validateWrite();

           if(this.grossWeight<this.tareWeight)

           {

               //this.TWeight = this.orig().TWeight;

               throw error("Gross Weight should be reereerr or equal to Tare Weight");

           }

           return ret;

  • Verified answer
    nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: DataEventHandler On validate write

    You should call validateWrite() only before insert/update, not in some calculation method.

    Also, you should not update values in validateWrite(). The user must be able to see the values that caused the issue!

    So, perhaps your code should look something like this:

       public void modifiedField(FieldId _fieldId)
       {
           next modifiedField(_fieldId);
           switch (_fieldId)
    
           {
    
               case fieldNum(WMSBillOfLadingOrder, grossWeight):
               case fieldNum(WMSBillOfLadingOrder, tareWeight):
                   this.calculateWeight();
                   break;
           }
       }
    
       void calculateWeight()
       {
             this.weight = this.grossWeight - this.tareWeight;
       }
    
       boolean validateWrite()
       {
           boolean ret= next validateWrite();
    
           if(ret && this.grossWeight < this.tareWeight)
           {
               ret = checkFailed("Gross Weight should be reereerr or equal to Tare Weight");
           }
    
           return ret;

    If something is missing, please try to describe the requirement with as much detail as you can. Like you would do if the other person knew nothing about the requirement. Because we don't know :)

    One more thing - why do you even need to store "Weight" separately? If it's always determined by Gross weight - Tare weight, why go through all the trouble of maintaining this sum in a third column? Seems like extra effort that's not really needed.

  • pavilionit Profile Picture
    87 on at
    RE: DataEventHandler On validate write

    this is the all code i use it

    [Extensionof(tableStr(WMSBillOfLadingOrder))]

    final class Training_WMSBillOfLadingOrder_Table_Extension

    {

       public void modifiedField(FieldId _fieldId)

       {

           ValidateEventArgs   validateArgs = e as ValidateEventArgs;

           WMSBillOfLadingOrder          WMSBillOfLadingOrder = sender as WMSBillOfLadingOrder;

           boolean             result = validateArgs.parmValidateResult();

           next modifiedField(_fieldId);

           switch (_fieldId)

           {

               case fieldNum(WMSBillOfLadingOrder, grossWeight):

               case fieldNum(WMSBillOfLadingOrder, tareWeight):

                   this.calculateWeight();

                   break;

           }

       }

       void calculateWeight()

       {

             this.validateWrite();

             this.weight = this.grossWeight - this.tareWeight;

       }

       boolean validateWrite()

       {

           boolean ret= next validateWrite();

           if(this.grossWeight<this.tareWeight)

           {

               //this.TWeight = this.orig().TWeight;

               throw error("Gross Weight should be reereerr or equal to Tare Weight");

           }

           return ret;

       }

    }

    and this is EvenHandle  method from a table i got it

    [DataEventHandler(tableStr(WMSBillOfLadingOrder), DataEventType::ValidatedWrite)]

    public static void WMSBillOfLadingOrder_onValidatedWrite(Common sender, DataEventArgs e)

    {      

     ValidateEventArgs   validateArgs = e as ValidateEventArgs;

       WMSBillOfLadingOrder          WMSBillOfLadingOrder = sender as WMSBillOfLadingOrder;

       boolean             result = validateArgs.parmValidateResult();

    }

    now

    how to write the method on  WMSBillOfLadingOrder_onValidatedWrite to get the true result

  • nmaenpaa Profile Picture
    101,160 Moderator on at
    RE: DataEventHandler On validate write

    I'm sorry, I don't understand your question. What do you need the event handler for? You're now using Chain of Command for the validateWrite method, so you don't need event handler for the same method.

    Regarding your code, it has issues as pointed out earlier, and I recommend to fix them before we move forward.

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…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 696 Super User 2025 Season 2

#2
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 569

#3
Martin Dráb Profile Picture

Martin Dráb 551 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans