Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Answered

Validation to find inbetween values

(0) ShareShare
ReportReport
Posted on by 110
Hi,

I have two fields min, max in a grid. The validation which I require is, the min and max range should be unique, as per below example, if I'm entering any values between 1 to 200 in next row, it should throw error as The range is already selected and cannot be used. It should allow to select the values after 200 only in next row for min field. 
How to check the condition for the ranges here and validate?
sl noMin Max
1150
251100
3101200
 
  • Verified answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,735 Super User 2024 Season 2 on at
    Validation to find inbetween values
    Hi RSX,
     
    You can use the next coding on the table, like below (assuming the name of your table is "MyTable":
     
    boolean validateWrite()
    {
        MyTable  myTableCheck;
        boolean  overlapFound;
    
    
        select firstonly RecId from myTableCheck
            where myTableCheck.Min >= this.Max
               && myTableCheck.Max <= this.Max
               && myTableCheck.RecId != this.RecId;
    
        if (myTableCheck.RecId != 0)
        {
            overlapFound = true;
        }
    
        select firstonly RecId from myTableCheck
            where myTableCheck.Min >= this.Min
               && myTableCheck.Max <= this.Min
               && myTableCheck.RecId != this.RecId;
    
        if (myTableCheck.RecId != 0)
        {
            overlapFound = true;
        }
    
        if (overlapFound)
        {
            return checkFailed("New values overlap with an existing range. Record can't be inserted.");
        }
    
        return true;
    }
     
  • RSX Profile Picture
    RSX 110 on at
    Validation to find inbetween values
    Hi Andre,
    Can you help me with the condition how we can check the entered value does not overlap the existing record in x++?
  • Suggested answer
    Kevin Xia Profile Picture
    Kevin Xia Microsoft Employee on at
    Validation to find inbetween values
    Hi,
    Here is an outline of the approach you can take:
    Client-Side Validation (JavaScript):
    • Attach an event handler to the OnValidate or OnChange event of the Min and Max fields in your form.
    • In the event handler, retrieve the values of the Min and Max fields for the current row.
    • Iterate through the grid to check if the entered range overlaps with any existing ranges. If it does, display an error message and prevent saving the record.
    Server-Side Validation:
    • Implement server-side validation to ensure data integrity.
    • Create a server-side method that checks for overlapping ranges in the data.
    • Call this method during the save operation, and if it detects an overlap, throw an error that prevents the record from being saved.
    Best regards,
    Kevin
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    André Arnaud de Cal... 291,735 Super User 2024 Season 2 on at
    Validation to find inbetween values
    Hi Community user,
     
    You can write x++ logic to validate the data on the validateWrite() function of the table. Then you can check using the entered values is there is an overlap with already existing records.

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,735 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,466 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans