应用到: CRM 2015 on-prem, CRM Online
Contains the data that’s needed to set the state of an entity record.
命名空间: Microsoft.Crm.Sdk.Messages
程序集: Microsoft.Crm.Sdk.Proxy (在 Microsoft.Crm.Sdk.Proxy.dll 中)
语法
声明
<DataContractAttribute(Namespace:="https://schemas.microsoft.com/crm/2011/Contracts")> _
Public NotInheritable Class SetStateRequest
    Inherits OrganizationRequest
[DataContractAttribute(Namespace="https://schemas.microsoft.com/crm/2011/Contracts")] 
public sealed class SetStateRequest : OrganizationRequest
示例
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.
// Create the Request Object
SetStateRequest state = new SetStateRequest();
// Set the Request Object's Properties
state.State = new OptionSetValue((int)IncidentState.Active);
state.Status = 
    new OptionSetValue((int)incident_statuscode.WaitingforDetails);
// Point the Request to the case whose state is being changed
state.EntityMoniker = caseReference;
// Execute the Request
SetStateResponse stateSet = (SetStateResponse)_serviceProxy.Execute(state);
// Check if the state was successfully set
Incident incident = _serviceProxy.Retrieve(Incident.EntityLogicalName, 
    _caseIncidentId, new ColumnSet(allColumns: true)).ToEntity<Incident>();
if (incident.StatusCode.Value == (int)incident_statuscode.WaitingforDetails)
{
    Console.WriteLine("Record state set successfully.");
}
else
{
    Console.WriteLine("The request to set the record state failed.");
}
备注
Message Availability
无论调用方是连接到服务器还是处于脱机状态,此消息都可正常工作。 Not all entity types support this message offline. See Supported Entities later in this topic.
Usage
Pass an instance of this class to the Execute method, which returns an instance of the SetStateResponse class.
Privileges and Access Rights
To perform this action, the caller must have privileges on the specified entity in the EntityMoniker property.
For a complete list of the required privileges, see SetState Privileges.
Valid State and Status value combinations
The valid combinations of state and status code values varies for many entities. For a list of default values for specific system entities, see Default status and status reason values.
For a list of the state and status values valid for custom entities in your organization, refer to the entity metadata.
若要查看您的组织的实体元数据,请安装浏览组织中的元数据中描述的元数据浏览器解决方案。您还可以在一个名为 EntityMetadata.xlsx 的 Excel 文件中查看非自定组织的元数据,该文件包含在 SDK 下载的顶级文件夹中。
Supported Entities
下表显示了支持此消息的默认实体,并说明此消息在调用方处于以下情形时是否可用:连接到服务器 (Server)、断开与服务器的连接 (Offline) 或二者 (Both)。
| Entity | Availability | 
|---|---|
| Account | 2 (Both) | 
| Appointment | 2 (Both) | 
| BusinessUnit | 2 (Both) | 
| Campaign | 2 (Both) | 
| CampaignActivity | 2 (Both) | 
| CampaignResponse | 2 (Both) | 
| Connection | 2 (Both) | 
| ConnectionRole | 2 (Both) | 
| Contact | 2 (Both) | 
| Contract | 2 (Both) | 
| ContractDetail | 2 (Both) | 
| ConvertRule | 2 (Both) | 
| DiscountType | 2 (Both) | 
| DynamicProperty | 2 (Both) | 
| 2 (Both) | |
| EmailServerProfile | 2 (Both) | 
| Entitlement | 2 (Both) | 
| Fax | 2 (Both) | 
| Goal | 2 (Both) | 
| GoalRollupQuery | 2 (Both) | 
| ImportMap | 2 (Both) | 
| Incident | 2 (Both) | 
| IncidentResolution | 2 (Both) | 
| Invoice | 2 (Both) | 
| KbArticle | 2 (Both) | 
| Lead | 2 (Both) | 
| Letter | 2 (Both) | 
| List | 2 (Both) | 
| Mailbox | 2 (Both) | 
| MailMergeTemplate | 2 (Both) | 
| Metric | 2 (Both) | 
| msdyn_PostAlbum | 2 (Both) | 
| msdyn_PostConfig | 2 (Both) | 
| msdyn_PostRuleConfig | 2 (Both) | 
| msdyn_wallsavedquery | 2 (Both) | 
| msdyn_wallsavedqueryusersettings | 2 (Both) | 
| Opportunity | 2 (Both) | 
| OpportunityClose | 2 (Both) | 
| OrderClose | 2 (Both) | 
| PhoneCall | 2 (Both) | 
| Position | 2 (Both) | 
| PriceLevel | 2 (Both) | 
| ProcessSession | 2 (Both) | 
| Product | 2 (Both) | 
| ProductAssociation | 2 (Both) | 
| Queue | 2 (Both) | 
| QueueItem | 2 (Both) | 
| Quote | 2 (Both) | 
| QuoteClose | 2 (Both) | 
| RecurringAppointmentMaster | 2 (Both) | 
| RelationshipRole | 2 (Both) | 
| RoutingRule | 2 (Both) | 
| SalesOrder | 2 (Both) | 
| SavedQuery | 2 (Both) | 
| SdkMessageProcessingStep | 2 (Both) | 
| ServiceAppointment | 2 (Both) | 
| SharePointDocumentLocation | 2 (Both) | 
| SharePointSite | 2 (Both) | 
| SLA | 2 (Both) | 
| SocialActivity | 2 (Both) | 
| SocialProfile | 2 (Both) | 
| SystemUser | 2 (Both) | 
| Task | 2 (Both) | 
| TransactionCurrency | 2 (Both) | 
| UoMSchedule | 2 (Both) | 
| UserQuery | 2 (Both) | 
| Workflow | 2 (Both) | 
继承层次结构
System.Object
   Microsoft.Xrm.Sdk.OrganizationRequest
    Microsoft.Crm.Sdk.Messages.SetStateRequest
线程安全性
此类型的所有公共静态(Visual Basic 中的 Shared)成员都是线程安全成员。不保证任何实例成员是线程安全成员。
平台
开发平台
Windows Vista、Windows Server 2003 和
目标平台
Windows Vista,Windows XP
Change History
另请参阅
参考
SetStateRequest 成员
Microsoft.Crm.Sdk.Messages 命名空间
SetStateResponse
其他资源
SetState Privileges
Sample: Validate Record State and Set State of the Record
How Role-Based Security Can Be Used to Control Access to Entities In CRM
How Instance-Based Security Can Be Used to Control Access to Entity Instances (Records) In CRM
Send comments about this topic to Microsoft.
© 2014 Microsoft Corporation. All rights reserved.