web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)
Answered

Do not allow non-duplicates in string value, except empty strings

(0) ShareShare
ReportReport
Posted on by 282

Hi all

Running Dynamics AX 2012 R3 CU9

Have run into a business requirement where we would like to ensure SalesTable.PurchOrderFormNum is set to not allow duplicates.

Normally I would do this with an index, but the field is blank by default, and does not get filled in for every order. I think the index would treat all the blank values as "duplicates".

Is there a way to not allow duplicates, but exclude empty values?

Cheers

Luke

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Sohaib Cheema Profile Picture
    49,677 Super User 2026 Season 1 on at

    Hi,

    one of the ways can be writing logic on validateWriteServer method of SalesTable.

    Create a new method on sales table as following

    public boolean PurchOrderFormNumAlreadyExists(CustPurchaseOrder _numberToFind,RefRecId _currentRecord)
    {
        boolean         ret;
        SalesTable      lclSalesTable;
        ;
        ret = false;
        lclSalesTable.clear();
        select firstOnly PurchOrderFormNum from lclSalesTable
            where lclSalesTable.PurchOrderFormNum == _numberToFind
                && lclSalesTable.RecId != _currentRecord;
        if(lclSalesTable.PurchOrderFormNum)
        {
            ret = true;
        }
        return ret;
    }

    Then call this method from  validateWriteServer  by writing following lines of code just above of, return ok;

    if(this.PurchOrderFormNum && this.PurchOrderFormNumAlreadyExists(this.PurchOrderFormNum,this.RecId))
        {
            ok = checkFailed('The Purchase Order form number already exists. Please use a new unique number.');
        }
  • lukbel Profile Picture
    282 on at

    Thanks for all your help folks :)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Andrew Jones a1x Profile Picture

Andrew Jones a1x 2

#2
Sagar Suman Profile Picture

Sagar Suman 2 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans