Sample code to connect Dynamics CE using OAuth and Deactivate the record.
Install the Microsoft.Xrm.Tooling.Connector assembly.
public static IOrganizationService GetCrmService1()
{
var connection = new CrmServiceClient(
"Url=https://pane-crm-tafp-dev.crm4.dynamics.com;" +
"Username=[username]@[domain].com;" +
"Password=password;" +
"AuthType=OAuth;"
+
"AppId=51f81489-12ee-4a9e-aaae-a2591f45987d;" +///User App Id
"RedirectUri=app://58145b91-0c36-4500-8554-080854f2ac97/;" + ///Azure Active Directory Id.
"LoginPrompt=Auto"
);
var service = connection.OrganizationWebProxyClient ??
(IOrganizationService)connection.OrganizationServiceProxy;
return service;
}
public static void ChangerecordStatusRecord()
{
IOrganizationService service =
GetCrmService1();
SetStateRequest activeState = new SetStateRequest()
{
State = new OptionSetValue(0),
Status = new OptionSetValue(1),
EntityMoniker = new EntityReference("ibm_consumerrole",
Guid.Parse("e0fd105b-8763-ee11-8df0-000d3a2e47ed")),
};
service.Execute(activeState);
SetStateRequest deactiveState = new SetStateRequest()
{
State = new OptionSetValue(1),
Status = new OptionSetValue(2),
EntityMoniker = new EntityReference("ibm_consumerrole",
Guid.Parse("e0fd105b-8763-ee11-8df0-000d3a2e47ed")),
};
service.Execute(deactiveState);
}
Comments
Post a Comment