Skip to main content

Notifications

Announcements

No record found.

Dynamics 365 Community / Forums / Finance forum / Validation to find inb...
Finance forum
Answered

Validation to find inbetween values

Posted on by 134
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... 288,768 Super User 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 134 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... 288,768 Super User 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.

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,768 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,985 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans