Hi Saeid,
Use the below code: function call ChangeStatusReason(service, recordGuid, entitySchemaName, outstandingamount);
private void ChangeStatusReason(IOrganizationService service, string recordId, string entityName, decimal outstandingamount)
{
Entity entActivate = new Entity(entityName);
SetStateRequest setStateActivate = new SetStateRequest();
setStateActivate.EntityMoniker = new EntityReference();
setStateActivate.EntityMoniker.Id = new Guid(recordId);
setStateActivate.EntityMoniker.Name = entityName;
setStateActivate.EntityMoniker.LogicalName = entActivate.LogicalName;
//Change Status to Paid if outstanding amount is 0 else Partially Paid
if(outstandingamount == 0)
{
setStateActivate.State = new OptionSetValue();
setStateActivate.State.Value = 0;
setStateActivate.Status = new OptionSetValue();
setStateActivate.Status.Value = 4;
service.Execute(setStateActivate);
}
else if (outstandingamount > 0)
{
setStateActivate.State = new OptionSetValue();
setStateActivate.State.Value = 0;
setStateActivate.Status = new OptionSetValue();
setStateActivate.Status.Value = 2;
service.Execute(setStateActivate);
}
}
Hope this helps.
Please marks the answer as yes.
Thanks
AKHIL