通过SOAP Web服务创建有关状态码和状态码不匹配的服务约会实体时出现错误:
4不是州代码的有效状态代码 ServiceAppointmentState.Open on serviceappointment。
基本上说reserved (statuscode 4)不是Open state (statecode 1)的成员。这是真的,它实际上是Scheduled state (statecode 3)的成员,但在我的请求中,我正确地将状态代码设置为3!
有谁知道为什么我的服务预约设置为Scheduled状态被忽略了?
完整请求:
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Create xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<entity xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts">
<a:Attributes xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<a:KeyValuePairOfstringanyType>
<b:key>statecode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>3</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>serviceid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>c5b8179c-3cab-e211-ab0a-00155d1438e9</a:Id>
<a:LogicalName>service</a:LogicalName>
<a:Name i:nil="true" />
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>scheduledend</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:dateTime">2013-06-13T14:30:00</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>statuscode</b:key>
<b:value i:type="a:OptionSetValue">
<a:Value>4</a:Value>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>subject</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:string">Support handover</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>scheduledstart</b:key>
<b:value xmlns:c="http://www.w3.org/2001/XMLSchema" i:type="c:dateTime">2013-06-13T09:00:00</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>py3_workpackageid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>dc7008cf-2eab-e211-ab0a-00155d1438e9</a:Id>
<a:LogicalName>py3_workpackage</a:LogicalName>
<a:Name i:nil="true" />
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>customers</b:key>
<b:value i:type="a:EntityCollection">
<a:Entities>
<a:Entity>
<a:Attributes>
<a:KeyValuePairOfstringanyType>
<b:key>partyid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>050d25a8-03c9-e211-866e-00155d143602</a:Id>
<a:LogicalName>account</a:LogicalName>
<a:Name i:nil="true" />
</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues />
<a:Id>00000000-0000-0000-0000-000000000000</a:Id>
<a:LogicalName>activityparty</a:LogicalName>
<a:RelatedEntities />
</a:Entity>
</a:Entities>
<a:EntityName i:nil="true" />
<a:MinActiveRowVersion i:nil="true" />
<a:MoreRecords>false</a:MoreRecords>
<a:PagingCookie i:nil="true" />
<a:TotalRecordCount>0</a:TotalRecordCount>
<a:TotalRecordCountLimitExceeded>false</a:TotalRecordCountLimitExceeded>
</b:value>
</a:KeyValuePairOfstringanyType>
<a:KeyValuePairOfstringanyType>
<b:key>resources</b:key>
<b:value i:type="a:EntityCollection">
<a:Entities>
<a:Entity>
<a:Attributes>
<a:KeyValuePairOfstringanyType>
<b:key>partyid</b:key>
<b:value i:type="a:EntityReference">
<a:Id>3e17fce0-e9cd-e211-866e-00155d143602</a:Id>
<a:LogicalName>systemuser</a:LogicalName>
<a:Name i:nil="true" />
</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues />
<a:Id>00000000-0000-0000-0000-000000000000</a:Id>
<a:LogicalName>activityparty</a:LogicalName>
<a:RelatedEntities />
</a:Entity>
</a:Entities>
<a:EntityName i:nil="true" />
<a:MinActiveRowVersion i:nil="true" />
<a:MoreRecords>false</a:MoreRecords>
<a:PagingCookie i:nil="true" />
<a:TotalRecordCount>0</a:TotalRecordCount>
<a:TotalRecordCountLimitExceeded>false</a:TotalRecordCountLimitExceeded>
</b:value>
</a:KeyValuePairOfstringanyType>
</a:Attributes>
<a:EntityState i:nil="true" />
<a:FormattedValues xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
<a:Id>00000000-0000-0000-0000-000000000000</a:Id>
<a:LogicalName>serviceappointment</a:LogicalName>
<a:RelatedEntities xmlns:b="http://schemas.datacontract.org/2004/07/System.Collections.Generic" />
</entity>
</Create>
</soap:Body>
</soap:Envelope>
从组织中删除解决方案时偶尔会发生同样的错误,因此我在研究问题时遇到了麻烦。我发现的只有this forum post,但似乎没有解决。
答案 0 :(得分:2)
statecode
是一个只读属性,在创建新记录时无法设置其值。
要设置正确的值,您需要始终使用SetStateRequest
http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest.aspx
结论:首先需要创建记录(并且它将处于打开状态)并在将其状态更改为保留后。