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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

How to create related entities in create PRODUCT operation?

(0) ShareShare
ReportReport
Posted on by

Hi,

I am working on CREATE operation for PRODUCT object.

Would like to know how to provide defaultuomscheduleid and defaultuomid using association with product? referring https://msdn.microsoft.com/en-us/library/gg328090.aspx#bkmk_associateOnCreate

I know the way to pass these values using by odata.bind (Associating Entities on Create) but would know how to create these related entities in one operation?

Below is the snippet for Associating defaultuomscheduleid and defaultuomid with create product operation:

{
   "name": "new product",
   "productnumber": "12345",
   "defaultuomscheduleid@odata.bind": "/uomschedules(54692a01-4c22-45eb-a224-a157b9a6a0b3)",
   "defaultuomid@odata.bind": "/uoms(d41f6ab2-6087-477b-a7f1-c4d1df10a57e)",
   "quantitydecimal": 0
}


How can I create these related entities in one CREATE PRODUCT operation?
Thanks

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at

    As far as I know you can't. You need to create these records first with a separate call for each record.

    And why would you want to do this?

  • Community Member Profile Picture
    on at

    Hi Martijn,

    I referred  msdn.microsoft.com/.../gg328090.aspx for CREATE operation. so, if you read section Create related entities in one operation you could find sample request for create account and in sample payload you will find primarycontactid which is navigation property (as per $metadata). this primarycontactid is nothing but Contact object. So in this one request you can create Account and Contact and this contact will automatically linked to account.

    And on other side if you see section Associate entities on create primarycontactid is used for associating existing contact object in account.

    So I was doing same thing for Product. Association is working fine for defaultuomscheduleid but would like to know how can I create this related entity while creating product?

    Thanks

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at

    I stil don't think you can do it when creating a product, since you are using a many to one relationship. The sample show how to create one to many records (account -> contact, opportunity and task).

    If you create a default schedule uom you might be able to create the uom record and the underlying products in one go.

    However I tried to do so, but since the complex relations of these it seems hard or even impossible to do so.

    I've come this far:

    {

       "name": "new unit group 2",

       "baseuomname" : "new unit group 2",

       "unit_of_measure_schedule_conversions" : [

           {

               "name" : "new unit 2",

               "quantity" : 1,

               "baseuom@odata.bind": "/uoms(d41f6ab2-6087-477b-a7f1-c4d1df10a57e)"

           }

       ]

    }

    But receive the following error: "The base unit does not belong to the schedule".

    I'm just wondering why you want to do this in one go?

  • Community Member Profile Picture
    on at

    Hi Martijn,

    Thanks for your reply.

    Actually I am working on integration of CRM with other API. So I am writing a code which will read $metadata and after that will retrieve the schema of entitytype Product in nodejs.

    So in metadata there are properties, complextypes, entitytypes, navigationproperties as well. so considering all these scenarios I want to generate schema which will consistent across all objects. that is why I wanted to make sure where can I support creating entities and creating association.

    Also would like to know how can I identify one-many and many-one relationship by looking $metadata?

  • Suggested answer
    JohnAnonymous Profile Picture
    5,241 on at

    Maybe this is what your looking for:

    msdn.microsoft.com/.../mt607833.aspx

    [Organization URI]/api/data/v8.1/RelationshipDefinitions -> Contains ManyToManyRelationshipMetadata EntityType and OneToManyRelationshipMetadata EntityType as both inherit from RelationshipMetadataBase EntityType.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans