Dynamics CRM 创建事件

Dynamics CRM create incident

我正在尝试通过他们的 API 在 Dynamics CRM 上创建事件。

当我尝试使用以下方法创建事件时,我成功地进行了授权:

    $accountsRequest = EntityUtils::getCreateCRMSoapHeader($CRMURL, $securityData).
'
      <s:Body>
            <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
            <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                    <b:KeyValuePairOfstringanyType>                         
                        <c:key>title</c:key>
                        <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">Its a sunday web case - second</c:value>
                    </b:KeyValuePairOfstringanyType>                     
                </b:Attributes>
                <b:EntityState i:nil="true"/>
                <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
                <b:Id>'.$accountId.'</b:Id>
                <b:LogicalName>incident</b:LogicalName>
                <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
            </entity>
            </Create>
        </s:Body>
    </s:Envelope>
    ';

$accountId looks like this:
dabc10e9-df02-e611-80d9-5065f38a9b01

我收到以下错误:

You should specify a parent contact or account.-2147204080 You should specify a parent contact or account.2016-04-15T07:59:11.6607106Z-2147204080 You should specify a parent contact or account.2016-04-15T07:59:11.6607106Z

知道我遗漏了什么吗?

编辑更新并试过这个:

'
      <s:Body>
            <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
            <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                    <b:KeyValuePairOfstringanyType>                         
                        <c:key>title</c:key>
                        <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">Its a sunday web case - second</c:value>
                    </b:KeyValuePairOfstringanyType>
                    <b:KeyValuePairOfstringanyType>
                        <c:key>customerid</c:key>
                        <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">19622e39-e502-e611-80da-5065f38ada41</c:value>
                    </b:KeyValuePairOfstringanyType>                                                              
                </b:Attributes>
                <b:EntityState i:nil="true"/>
                <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
                <b:Id>00000000-0000-0000-0000-000000000000</b:Id>
                <b:LogicalName>incident</b:LogicalName>
                <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>                    
            </entity>
            </Create>
        </s:Body>
    </s:Envelope>
    ';

但还是一样的错误

编辑#2,也试过:

'
      <s:Body>
            <Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
            <entity xmlns:b="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
                <b:Attributes xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
                    <b:KeyValuePairOfstringanyType>                         
                        <c:key>title</c:key>
                        <c:value i:type="d:string" xmlns:d="http://www.w3.org/2001/XMLSchema">Its a sunday web case - second</c:value>
                    </b:KeyValuePairOfstringanyType>
                    <b:KeyValuePairOfstringanyType>
                        <c:key>customerid</c:key>
                        <b:value i:type="a:EntityReference">
                           <a:Id>19622e39-e502-e611-80da-5065f38ada41</a:Id>
                           <a:LogicalName>account</a:LogicalName>
                           <a:Name i:nil="true" />
                        </b:value>
                    </b:KeyValuePairOfstringanyType>                                                              
                </b:Attributes>
                <b:EntityState i:nil="true"/>
                <b:FormattedValues xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>
                <b:Id>00000000-0000-0000-0000-000000000000</b:Id>
                <b:LogicalName>incident</b:LogicalName>
                <b:RelatedEntities xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic"/>                    
            </entity>
            </Create>
        </s:Body>
    </s:Envelope>
    ';

我收到错误:

DeserializationFailedThe formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://schemas.microsoft.com/xrm/2011/Contracts/Services:entity. The InnerException message was 'Error in line 68 position 57. 'EndElement' 'KeyValuePairOfstringanyType' from namespace 'http://schemas.microsoft.com/xrm/2011/Contracts' is not expected. Expecting element 'value'.'. Please see InnerException for more details.

您似乎正在尝试将帐户 ID 值放入 Id 属性中。 Id 属性指的是事件的 ID...最好让 CRM 为您生成 ID,因此不要为 Id 属性提供任何内容(除非您有意尝试设置新事件的 ID)。

错误指的是 EntityReference 类型的 customerid 属性。 EntityReferences 具有 Id 和 LogicalName 属性。将您的 $accountId 值放入 customerid.Id,并使 customerid.LogicalName 成为 "account"。 EntityReferences 也有名称 属性,但您不必提供它。

您的编辑 #2 看起来可能存在一些命名空间问题。试试这个:

<b:KeyValuePairOfstringanyType>
    <c:key>customerid</c:key>
    <c:value i:type="b:EntityReference">
       <b:Id>19622e39-e502-e611-80da-5065f38ada41</b:Id>
       <b:LogicalName>account</b:LogicalName>
       <b:Name i:nil="true" />
    </c:value>
</b:KeyValuePairOfstringanyType>