web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Suggested Answer

Relation between two fields is not working when inserting records via x++

(0) ShareShare
ReportReport
Posted on by 2,011
Hi,

I have a parent table (TableX) with mandatory (Field1) which is also an index with allow duplicate No.
This Field1 has an EDT, which has TableRelations and TableReferences Nodes filled for it.

Now I created a new table(TableY) which has Field1(same Edt). Field1 in this table is not unique and not mandatory. It also has ignoreEdtRelation = true.
I also created a relation between these two tables on TableY based on Field1.

When I open the form for TableY, and try to fill Field1 with a value that doesn't exist in TableX, it doesn't allow me. it only allows empty value or an existing value from TableX -- which is the expected behaviour because of the relation.

However, If i try to insert a record for TableY by code, where I fill Field1 with a value that doesn't exist in TableX -- it allows me to do so... why is that? how can i prevent that and make it work like it works from the UI?
I have the same question (0)
  • Martin Dráb Profile Picture
    240,198 Most Valuable Professional on at
    Didn't you forget to call validateWrite() method and check its result before inserting the (potentially invalid) record?
  • .. Profile Picture
    2,011 on at
    Hi Martin,

    I'm calling validateWrite before adding to the recordInsertList  and it's not working--- but do you mean i need to put this validation inside the validateWrite or should it work by itself?
  • Bharani Preetham Peraka Profile Picture
    3,634 Moderator on at
    Ideally if you call validatewrite() then if there is some relation, it should give error even without giving code in validation if it is defined at table level. If it is not working means have you written code like skipdatamethods(true); something like this? Can you send your code?
  • Suggested answer
    Martin Dráb Profile Picture
    240,198 Most Valuable Professional on at
    The system doesn't automatically make extra SQL statements to check the validity on saving. If the values come from an unreliable source, your code normally should validate them before using them.
     
    When you already have in your table buffer, you can validate them with validateField(), which checks the related table too. That's the method that forms call when you modify a value of a field (even before saving the record).
     
    If you wish, you call validateField() from validateWrite() 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

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 June Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 382 Super User 2026 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 265 Most Valuable Professional

#3
Subra Profile Picture

Subra 262

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans