Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

Check if data already exists, prompt error

Posted on by 55

Hi all,

I got new customize fields in AP Invoice Journal. Forwarder Info which consist three new fields A, B and C. The requirement is if the user key in the A, B, and C field for one invoice, in another invoice if user key in the same data as the first one it will prompt duplicate error. 

if (ledgerJournalTrans.A && ledgerJournalTrans.B && ledgerJournalTrans.C)
{
            isValid = checkFailed("Fowarderd info data duplicate detected!");
}


This is my code in validate write but it seems to prompt up error on other place also. any advice? 

Thank you. 

*This post is locked for comments

  • fathin Profile Picture
    fathin 55 on at
    RE: Check if data already exists, prompt error

    It's work. Thank you so much.

  • Verified answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Check if data already exists, prompt error

    So you want to find out if there is another LedgerJournalTrans that has same values for fields A, B and C than the current one? And if there is such LedgerJournalTrans, you want to show an error.

    Try this:

    LedgerJournalTrans ledgerJournalTransDuplicate;
    
    if (this.A || this.B || this.C)
    {
        select firstonly RecId from ledgerJournalTransDuplicate
    	    where ledgerJournalTransDuplicate.A == this.A
    	       && ledgerJournalTransDuplicate.B == this.B
                   && ledgerJournalTransDuplicate.C == this.C
    	       && ledgerJournalTransDuplicate.RecId != this.RecId;
    
        if (ledgerJournalTransDuplicate.RecId)
        {
            isValid = checkFailed("Data duplicate detected!");
        }
    }


  • fathin Profile Picture
    fathin 55 on at
    RE: Check if data already exists, prompt error

    I set it as this but it didn't work

    if (ledgerJournalTrans.JournalNum != ledgerJournalTransDuplicate)
    {
        if (ledgerJournalTransDuplicate.A && ledgerJournalTransDuplicate.B && ledgerJournalTransDuplicate.C)
        {
            isValid = checkFailed("Data duplicate detected!");
        }
    }


  • Suggested answer
    nmaenpaa Profile Picture
    nmaenpaa 101,156 on at
    RE: Check if data already exists, prompt error

    Yes, you can set any criteria you need.

  • fathin Profile Picture
    fathin 55 on at
    RE: Check if data already exists, prompt error

    Can I specific the journal number instead?

    if this Journal number != to the current journal number, prompt error.

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Check if data already exists, prompt error

    To get the specific journal type, select the LedgerJournalTable using JournalNum and then put LedgerJournalTable.JournalType == LedgerJournalType::VendInvoiceRegister for identifying AP invoice journal.

  • fathin Profile Picture
    fathin 55 on at
    RE: Check if data already exists, prompt error

    Is there any example?

    Thank you

  • Suggested answer
    Ajit Profile Picture
    Ajit 8,755 on at
    RE: Check if data already exists, prompt error

    You can specify the journal type as well.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,253 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans