You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过API调用在Dynamics CRM中关联自关联N:N的自定义实体rooms实例?

Hey there! Let’s tackle your two questions about working with your self-referential N:N rooms custom entity in Dynamics CRM via API—super common use case, so I’ve got you covered:

Question 1: Can I associate new instances of the rooms entity with each other via API calls?

Absolutely you can! Dynamics CRM’s Web API (and Organization Service, if you prefer SOAP) fully supports creating N:N relationships between entity records—including custom self-referential ones like your rooms entity. Here’s how to do it with the Web API:

  • First, confirm you have the logical name of your N:N relationship (you’ll find this in CRM’s customization area under the rooms entity’s Relationships tab—it’ll look something like new_rooms_rooms, depending on how you named it).
  • To link two existing rooms records, send a POST request to the Associate action endpoint for one of the records:
    POST [Your CRM Org URI]/api/data/v9.2/rooms(<first-room-id>)/Microsoft.Dynamics.CRM.Associate
    
  • Include this JSON body to specify the relationship and the second room to link:
    {
      "target": {
        "entitysetname": "rooms",
        "entities": [
          {
            "id": "<second-room-id>",
            "logicalname": "new_rooms"
          }
        ]
      },
      "relationship": {
        "relationshipname": "new_rooms_rooms"
      }
    }
    
  • If you’re creating a new rooms record and want to immediately associate it with an existing one: first POST to /rooms to create the new record, grab its ID from the response, then run the Associate action above using that new ID.
Question 2: How to associate custom objects via API calls in CRM?

Associating custom entities works slightly differently depending on the relationship type (N:N, 1:N, N:1), but the core API patterns are consistent:

Follow the same process outlined in Question 1. The key rules here are:

  • Always use the relationship’s logical name (not the friendly display name) in your request.
  • You can associate multiple records at once by adding more entries to the entities array in the request body.

For 1:N or N:1 Relationships

If you’re linking a child record to a parent (e.g., a custom booking entity to a room), you have two simple options:

  1. Set the lookup when creating the child record:
    When sending a POST to create the child record, include the lookup field with the parent’s ID:
    {
      "new_bookingname": "Conference Room Booking #456",
      "new_roomid": {
        "id": "<target-room-id>",
        "logicalname": "new_rooms"
      }
    }
    
  2. Associate after creation:
    Use a PATCH request to update the child record’s lookup field with a binding to the parent:
    PATCH [Your CRM Org URI]/api/data/v9.2/new_bookings(<booking-id>)
    
    Request body:
    {
      "new_roomid@odata.bind": "/rooms(<target-room-id>)"
    }
    

Quick Pro Tips

  • Stick to the latest API version (e.g., v9.2) for the most stable and feature-rich experience.
  • Double-check all logical names (entity, field, relationship) — CRM uses these internally, so typos will throw errors.
  • If you’re using the Organization Service (SOAP), use the AssociateRequest class for N:N links, or set the lookup property directly for 1:N/N:1 links.

内容的提问来源于stack exchange,提问作者Russell Quao

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.13 08:49:24