Skip to main content

Notifications

Announcements

No record found.

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)
{       
}

  • Martin Dráb Profile Picture
    232,011 Most Valuable Professional on at
    RE: DataEventHandler On validate write

    Dear pavilionit, please stop selecting all categories for all your questions. For example, how is this question related to "continuous updates" or "Management Reporter"? It seems to me that "Development / Customization / SDK" is the only fitting category.

    I'm going to fix all your threads, but please make sure you do it correctly next time. Thank you.

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

    thanks for helping me

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

    Hi pavillionit,

    I suggest you to search the web for existing documentation, blogs and discussions. And if you need general help with event handler syntax, please post a new question. Also could you mark the helpful answer(s) as verified if your original problem is now solved? Thanks!

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

    firstly thanks for your help

    if you can just for me

    show me how to set or build event handler to improve my skills and thanks again

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

    Hi pavillionit,

    yes I understand this requirement. But the validateWrite() of your Chain of Command class is already doing it. So you don't need an event handler to do the same thing again! Just take the code that I shared earlier and try it. If you have some problems with it, investigate them, and let us know if you need help.

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

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

    when i insert value must be validate for the number if gross greater than tare the value for weight is changed and if gross less than tare i need show message to customer

  • nmaenpaa Profile Picture
    101,156 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.

  • 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

  • Verified answer
    nmaenpaa Profile Picture
    101,156 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 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;

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

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

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 293,278 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,011 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans