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

How to select between two fields without overlapping

(0) ShareShare
ReportReport
Posted on by 454

Hi,

I have one Table which is having two fields "From" and "To". I need to select between these fields. If i enter a new value in the table , if the entered value in the "From" overlaps between the previously entered values. It should not accept the value to be inserted.

For eg:   The 1 to 1500 already inserted, if i try to enter 10 to 1000 it should not be inserted. Help me on this. TIA 

From  TO
1 1500
10 1000

Regards,

Ram

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to select between two fields without overlapping

    These codes check whether the fields are in range individually. It doesn't matter which field is big. If either of them is in range, the old record will return.

    If you want to add a new condition (from not greater than to), simply compare the new record.

    if (tableInsert.From> tableInsert.To)

    If you don't have such a request, the above codes will do the trick.

  • Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: How to select between two fields without overlapping

    If you look at code samples above, you can see how to compare fields. What else do you need? Please elaborate.

  • Ram Kumar Profile Picture
    454 on at
    RE: How to select between two fields without overlapping

    Hi Ergun,

    I have one condition which is the To value should be greater than From Value. How it should be written.

    regards,

    Ram

  • Ram Kumar Profile Picture
    454 on at
    RE: How to select between two fields without overlapping

    Thanks Martin, Ergun . I have confused with the buffers sorry. It works

    Regards,

    Ram

  • ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to select between two fields without overlapping

    Dont you have two record (an old and a new).

  • Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: How to select between two fields without overlapping

    It's the same table. But you need two buffers - the one that you're saving and the other for finding existing records.

  • Ram Kumar Profile Picture
    454 on at
    RE: How to select between two fields without overlapping

    Hi Ergun,

    I have to compare between two fields in only one table.

    Regards,

    Ram

  • Verified answer
    Martin Dráb Profile Picture
    231,758 Most Valuable Professional on at
    RE: How to select between two fields without overlapping

    What exactly is the problem?

    You don't know how to validate records on save? If so, use validateWrite() method and return false if the check fails.

    Or you don't know how to compare values? You have operators like >, <, >= and <=.

    Or you don't know what logic you need to find conflicting records? What about something like this:

    select firstOnly RecId from myTable
    where (myTable.From < this.From && myTable.To > this.From)
       || (myTable.From > this.To && myTable.To < this.To);

  • Suggested answer
    ergun sahin Profile Picture
    8,816 Moderator on at
    RE: How to select between two fields without overlapping

    If I am not wrong you want not only "from" but "to" do must not between these fields. Maybe something like this;

    Table   tableInsert, tableCheck;
    
    tableInsert.From    = 10;
    tableInsert.To      = 120;
    
    select firstOnly tableCheck
        where(tableCheck.From  >= tableInsert.From
           && tableCheck.To    <= tableInsert.From)
           ||(tableCheck.From  >= tableInsert.To
           && tableCheck.To    <= tableInsert.To);
           
    if(tableCheck)
    {
        error("..");
    }

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... 292,884 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,758 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Product updates

Dynamics 365 release plans