Skip to main content

Notifications

Microsoft Dynamics AX (Archived)
Answered

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

(0) ShareShare
ReportReport
Posted on by 280

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

  • lukbel Profile Picture
    lukbel 280 on at
    RE: Do not allow non-duplicates in string value, except empty strings

    Thanks for all your help folks :)

  • Verified answer
    Sohaib Cheema Profile Picture
    Sohaib Cheema 46,612 User Group Leader on at
    RE: Do not allow non-duplicates in string value, except empty strings

    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.');
        }

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,969 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,842 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans