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)

How to create a method to check record repeat and show info

(0) ShareShare
ReportReport
Posted on by 319

Hi All,

When user key a record, if itemid is repeat, how to show a message to reminder?

How I create the method in DataSource or Form Design, could used the override method??

thanks in advance.

170628checkduplicate.jpg

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Do you mean once user creates a record, if so there are many ways to accomplish this.One way is to get count of records in the validatewrite method of the datasource.

    Here InventJournalTrans is the form datasource and gets the selected record on grid.

    public boolean validateWrite()

    {

    InventJournalTrans trans;

    ret = super();

    select count(RecId) from trans

           where trans.ItemId == InventJournalTrans.ItemId

           && trans.JournalId == InventJournalTrans.JournalId;

       if (trans.RecId > 1)

       {

           info("ItemId Repeat");

       }

    }

    return ret;

    }

    If you want to stop record from creation, simply you can create an unique index on inventjournalTrans based on journaltype.

    Hope this helps you.

    Thanks,

    Chaitanya Golla

  • ATMA-Jen Profile Picture
    319 on at

    Hello Golla,

    Thanks for your help in advance.

    I Try your code and run,

    but no show info message?

    please tell me why?

    code:

    170629TryRunRepeat01.jpg

    Run:

    170629TryRunRepeat01.jpg

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    Please don't comment any base code, rather add your code to the method.

    Your code in validate write should look like the following

    public boolean validateWrite()

    {

       InventJournalTrans trans;

       boolean ret;

       inventJournalTrans.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;

       ret = super();

       ret = journalFormTrans.datasourceValidateWritePost(ret);

       select count(RecId) from trans

           where trans.ItemId == InventJournalTrans.ItemId

           && trans.JournalId == InventJournalTrans.JournalId;

       if (trans.RecId > 1)

       {

           info("Repeat");

       }

       return ret;

    }

  • ATMA-Jen Profile Picture
    319 on at

    Hello Golla,

    Got it & thanks a lot....

    I try again, but really want to know why not work??

    170629TryRepeat02.jpg

    170629TryRepeat02.jpg

  • Suggested answer
    Chaitanya Golla Profile Picture
    17,225 on at

    Hi,

    In the screenshot I couldn't find the base code. Please retain the base code and add this new code to it or else just copy paste the validatewrite method I provided.

    Thanks,

    Chaitanya Golla

  • ATMA-Jen Profile Picture
    319 on at

    Try again: (Poor English)

    Still no work:

    170629TryRunRepeat03.jpg

    170629TryRunRepeat03.jpg

  • ATMA-Jen Profile Picture
    319 on at

    Hello Chaitanya Golla,

    Thanks for your help.

    I debug:

    I New  2 Itemid , and click the validate button, then it's OK,

    I check the code and  trans.RecId =1

    I don't know why??

    170629TryRunRepeatDebug01.jpg

  • ATMA-Jen Profile Picture
    319 on at

    Hello,

    I Debug:

    When I new one row data, trans.RecID=0,

    when I new two same rows data, trans.RecID=1,

    I don't Know Why??

    170629DebugCheckItemId02_2D00_2.jpg

    170629DebugCheckItemId02_2D00_2.jpg

    170629DebugCheckItemId02_2D00_3.jpg

    So, I edit the code is

    if (trans.RecId > 0)
    {
    info('Repeat');
    }

    I thins It's OK.

    Thank you very much for you help kindly.

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 39

#2
Michel ROY Profile Picture

Michel ROY 14

#3
imran ul haq Profile Picture

imran ul haq 8

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans