statuscode and statecode mismatch even though both are explicitly set

陌路散爱 提交于 2019-12-24 17:14:50

问题


I'm getting an error when creating a service appointment entity through the SOAP webservice about a mismatch between statuscode and statecode:

4 is not a valid status code for state code ServiceAppointmentState.Open on serviceappointment.

Essentially saying that reserved (statuscode 4) isn't a member of the Open state (statecode 1). Which is true, it's actually a member of the Scheduled state (statecode 3) but in my request I'm correctly setting statecode to 3!

Does anyone know why my setting the serviceappointment to the Scheduled state is being ignored?


full request:

<?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>

it appears the same error occasionally happens when deleting solutions from an organisation so I've had trouble researching the issue. All I've found is this forum post, but it doesn't seem to be resolved.


回答1:


statecode is a readonly property, you can't set its value when you create a new record.

To set the right value you need to use always a SetStateRequest

http://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest.aspx

Conclusion: first you need to create the record (and it will be in open state) and after change its status to reserved.



来源:https://stackoverflow.com/questions/17070495/statuscode-and-statecode-mismatch-even-though-both-are-explicitly-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!