Thursday, September 23, 2010

Getting userId and Information

CrmService _service = new CrmService();
CrmAuthenticationToken token = new CrmAuthenticationToken();
token.OrganizationName = orgName;
token.AuthenticationType = AuthenticationType.AD;
_service.Url = "http://localhost:5555/MSCRMServices/2007/crmservice.asmx";
_service.CrmAuthenticationTokenValue = token;
//_service.Credentials = new System.Net.NetworkCredential() { UserName = "username", Password = "password" };
_service.Credentials = System.Net.CredentialCache.DefaultCredentials;
WhoAmIRequest req = new WhoAmIRequest();
WhoAmIResponse res = (WhoAmIResponse)_service.Execute(req);
Guid userID= res.UserId;

After getting UserId get the whole information by TargetRetrieved or Query;

How to get preOwner and postOwner in Plugin


SecurityPrincipal assignee = (SecurityPrincipal)context.InputParameters.Properties["Assignee"];

Guid guidNewOwner = assignee.PrincipalId;

Moniker moniker = (Moniker)context.InputParameters.Properties["Target"];

Guid id = moniker.Id;

//pass this id and get owner id from lead

ICrmService service = context.CreateCrmService(true);

Guid guidOldOwner = GetOwner(id.ToString(), service);


How to fire a Workflow through Plugin

ExecuteWorkflowRequest request = new ExecuteWorkflowRequest();

//Assign the ID of the workflow you want to execute to the request.

request.WorkflowId = new Guid("stringWorkFlowid");

//Assign the ID of the entity to execute the workflow on to the request.

request.EntityId = id;

// Execute the workflow.

ExecuteWorkflowResponse response = (ExecuteWorkflowResponse)service.Execute(request);