Dynamics 365 make invoice active and Paid using C#.net code or plugin
foreach (var item in ERPInvoices.Entities)
{
// Set active
SetStateRequest setStateRequest = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = new Guid(item["invoiceid"].ToString()),
LogicalName = "invoice",
},
State = new OptionSetValue(0),
Status = new OptionSetValue(1)
};
_CrmService.Execute(setStateRequest);
// Update the field
Entity invoiceToUpdate = new Entity("invoice");
invoiceToUpdate.Id = item.Id;
if (issendfullyerp)
{
invoiceToUpdate.Attributes["has_issendfullyerp"] = true;
}
if (issendpartiallyerp)
{
invoiceToUpdate.Attributes["has_issendpartiallyerp"] = true;
}
_CrmService.Update(invoiceToUpdate);
//set abck paid - to old status
SetStateRequest request = new SetStateRequest()
{
EntityMoniker = new EntityReference
{
Id = new Guid(item["invoiceid"].ToString()),
LogicalName = "invoice",
},
State = new OptionSetValue(2),
Status = new OptionSetValue(100001),
};
_CrmService.Execute(request);
}