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

Validation to find inbetween values

(0) ShareShare
ReportReport
Posted on by 202
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
    294,141 Super User 2025 Season 1 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
    202 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
    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
    294,141 Super User 2025 Season 1 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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March 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... 294,141 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,892 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans