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 :
Small and medium business | Business Central, N...
Suggested Answer

Unique record in table

(0) ShareShare
ReportReport
Posted on by 305

Hi

I want to insert a record simultaneously in two tables by entering the data in one card page. I wrote the code for inserting into another table inside the OnClosePage trigger of the card. It saves a new record fine but gives an error on reopening and then closing the page for the same record(the record with the same primary key already exist). How do I fix it? Am I using the wrong trigger or is there any validation statement that I need to put to check whether the record already exist?

Thanks

Khudeja

  • Hannes Holst Profile Picture
    5,767 on at

    Hi,

    You could add something like this

    If not YourTable.Get(YourPrimaryKey) then
      CreateNewRecord();

  • Suggested answer
    Avinash B Profile Picture
    1,455 on at

    Hi

    You can also make use of the SetRecFilter.

    RecVariable.Init();

    .

    .

    .// Assign the values to the RecVariable

    .

    RecVariable.SetRecFilter();

    If RecVariable.IsEmpty() then

       RecVariable.Insert() // Insert the record if hasn't found

    Else

       RecVariable.Modify(); // Modifies the existing record (if any changes).

    Regards

    Avinash B

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 719 Super User 2026 Season 2

#2
YUN ZHU Profile Picture

YUN ZHU 410 Super User 2026 Season 2

#3
AndrewThomas81 Profile Picture

AndrewThomas81 369 Super User 2026 Season 2

Last 30 days Overall leaderboard

Featured topics

Microsoft Training Manuals

Product updates

Dynamics 365 release plans