【问题标题】:how to execute crm book action via web api?如何通过 web api 执行 crm book 操作?
【发布时间】:2018-07-30 06:44:44
【问题描述】:

CRM 公开actions,它允许您通过 Web API 执行它们。

例如以下是WinOpportunity 操作架构和API:

<Action Name="WinOpportunity">
  <Parameter Name="OpportunityClose" Type="mscrm.opportunityclose" Nullable="false" />
  <Parameter Name="Status" Type="Edm.Int32" Nullable="false" />
</Action>

要执行这个问题,您需要发布以下内容:

POST [Organization URI]/api/data/v8.2/WinOpportunity HTTP/1.1
Accept: application/json
Content-Type: application/json; charset=utf-8
OData-MaxVersion: 4.0
OData-Version: 4.0

{
 "Status": 3,
 "OpportunityClose": {
  "subject": "Won Opportunity",
  "opportunityid@odata.bind": "[Organization URI]/api/data/v8.2/opportunities(b3828ac8-917a-e511-80d2-00155d2a68d2)"
 }
}

有没有办法执行 BookRequest 动作?

在检查 CSDL 架构时,我发现这个动作被定义为:

<Action Name="Book">
<Parameter Name="Target" Type="mscrm.crmbaseentity" Nullable="false"/>
<Parameter Name="ReturnNotifications" Type="Edm.Boolean"/>
<ReturnType Type="mscrm.BookResponse" Nullable="false"/>
</Action>

此 Book 操作的请求是什么样的?

【问题讨论】:

    标签: c# dynamics-crm crm dynamics-crm-2016 dynamics-crm-webapi


    【解决方案1】:

    引用MSDNBookRequest 消息期望AppointmentTargetBook 操作也是如此。

    // Create the ActivityParty instance.
    ActivityParty party = new ActivityParty
    {
        PartyId = new EntityReference(SystemUser.EntityLogicalName, userResponse.UserId)
    };
    
    // Create the appointment instance.
    Appointment appointment = new Appointment
    {
        Subject = "Test Appointment",
        Description = "Test Appointment created using the BookRequest Message.",
        ScheduledStart = DateTime.Now.AddHours(1),
        ScheduledEnd = DateTime.Now.AddHours(2),
        Location = "Office",
        RequiredAttendees = new ActivityParty[] { party },
        Organizer = new ActivityParty[] { party }                        
    };                    
    
    // Use the Book request message.
    BookRequest book = new BookRequest
    {
        Target = appointment
    };
    

    引用MSDN,webapi 请求可能如下所示:(正在使用现有的约会记录,仍然收到 400 Bad request)

    POST [Organization URI]/api/data/v8.2/Book HTTP/1.1
    Accept: application/json
    Content-Type: application/json; charset=utf-8
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    
    {
     "Target": {
      "activityid": "59ae8258-4878-e511-80d4-00155d2a68d1",
      "@odata.type": "Microsoft.Dynamics.CRM.appointment"
     }
    }
    

    【讨论】:

    • 这似乎不正确。 “类型‘Microsoft.Dynamics.CRM.crmbaseentity’上不存在属性‘主题’——与描述、scheduledstatart 等相同......
    • The following example shows how to use this message. For this sample to work correctly, you must be connected to the server to get an IOrganizationService interface. For the complete sample, see the link later in this topic.
    • 正在 CRM rest builder 中测试.. 等待
    猜你喜欢
    • 1970-01-01
    • 2019-02-09
    • 1970-01-01
    • 2014-11-23
    • 1970-01-01
    • 2020-05-10
    • 2017-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多