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,679 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!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the March Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 16

#2
GiacomoRovai Profile Picture

GiacomoRovai 4

#3
Douglas Noel Profile Picture

Douglas Noel 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans