How to change State/Status in CRM 2013 using c#

六月ゝ 毕业季﹏ 提交于 2019-12-11 01:34:29

问题


How do I change State and/or Status of an entity in CRM 2013 using C#?

Neither CRM 2011's SetStateRequest nor the earlier SetStateDynamicEntityRequest are being recognized. Searching online didn't seem to help either... Am I missing a namespace or something?

Thanks in advance

Namespaces:

using System;  
using System.Collections;  
using System.Collections.Generic;  
using System.Linq;  
using System.Text;  
using System.Net;  
using Microsoft.Xrm.Sdk;  
using Microsoft.Xrm.Sdk.Client;  
using Microsoft.Xrm.Sdk.Query;  
using Microsoft.Xrm.Sdk.Discovery;  
using Microsoft.Xrm.Sdk.Messages;  
using System.ServiceModel;  
using System.ServiceModel.Description;  
using System.Web.Services.Protocols;  

The function:

private void changeUserStatus(Guid userId, IOrganizationService service, int state)  
{  
    SetStateRequest setStateRequest = new SetStateRequest  
    {  
        EntityMoniker = new EntityReference("systemuser", userId),  
        State = new OptionSetValue(state),  
        Status = new OptionSetValue(-1),  
    };  
    service.Execute(setStateRequest);  
}  

IMPORTANT: My SetStateRequest is NOT recognized by visual studio 2012, so unlike the above example it's not highlighted and actually red underlined with the "the type or namespace not found" message displayed when hovering

Edit: I see the question got downvoted and I'm sorry if I'm missing something but I really have no more information to provide apart from the fact that I've spent 4 hours yesterday looking for this online (including stackoverflow) without any avail. I may be using the wrong search criteria or looking in the wrong places, but if that's the case could anyone at least point me in the right direction? I'm a beginner on all of this (both stackoverflow and crm2013) and I'm kind of stuck on this. Thanks again


回答1:


You are not referencing microsoft.crm.sdk.proxy.dll and its namespace Microsoft.Crm.Sdk.Messages

so the code will be

using Microsoft.Crm.Sdk.Messages;

Another thing, be sure that the int values for State and Status are valid for the entity (in your case systemuser)



来源:https://stackoverflow.com/questions/20638702/how-to-change-state-status-in-crm-2013-using-c-sharp

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