Skip to main content

Notifications

Small and medium business | Business Central, N...
Suggested answer

How to create a new entity and link to another entity in a single request via API?

(0) ShareShare
ReportReport
Posted on by 15

Hi,

Sorry for submitting another question. I can't seem to reply to the other. I receive an error in both Chrome and Edge.

Further to previous enquiries, I have found a similar issue when creating a new entity that has a key that is effectively a foreign key to another entity type.

I have Vendors and Vendor Bank Accounts. The Vendor Bank Account has an ID and Vendor Number as keys. The Vendor Number determines the relationship between the two entities.

When I do a POST to create a Vendor Bank Account I provide the ID and Vendor Number in the body...

.../OData/Company('XXX')/Vendor_Bank_Account_Card

{

"Vendor Number": "10",

"ID": "1"

}

(Also tried "Vendor_Number")

However I receive a message...

The Vendor Bank Account already exists. Identification fields and values: Vendor Number='',ID='1'

The request doesn't seem to recognise the Vendor Number value.

Any assistance would be greatly appreciated as the issue is driving me crazy.

  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 74,036 Super User 2024 Season 2 on at
    RE: How to create a new entity and link to another entity in a single request via API?

    Hi, the primary key of table Vendor Bank Account (288) is Code and Vendor No..

    It looks like you are publishing standard Vendor Bank Account Card (425) page into a WebService. When entering Code on this page, the Vendor Number is automatically Validated. But when you use Post externally, the code executed may not be correct. So I suggest you don't use the standard page, create a new Vendor Bank Account page, and then publish it to the Web Service

    pastedimage1643935448511v1.png

    Hope this will help.

    Thanks.

    ZHU

  • RE: How to create a new entity and link to another entity in a single request via API?

    Hello,

    Thank you for asking. I have not seen the other post you mention, so apologies if I send you info you already know, but I think you are looking for "deep insert", for example like shown here www.kauffmann.nl/.../ .

    If the linked record is blank, I think it may have to do with the page design, and a link property there, more than the API call itself. I don't know if this helps you?

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

News and Announcements

Announcing Category Subscriptions!

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 Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans