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

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
 
I have the same question (0)
  • Suggested answer
    André Arnaud de Calavon Profile Picture
    299,059 Super User 2025 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.
  • 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
  • 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++?
  • Verified answer
    André Arnaud de Calavon Profile Picture
    299,059 Super User 2025 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;
    }
     

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

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

#1
CA Neeraj Kumar Profile Picture

CA Neeraj Kumar 2,177

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 593 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans