hi
I just want to cancel a workflow programatically using c#. I'm using the following code to do that
using (ServiceContext serviceContext = new ServiceContext(service))
{
var processes = (from p in serviceContext.CreateQuery<AsyncOperation>()
where p.PrimaryEntityType == "entity name"
&& p.RegardingObjectId.Id == "entityId"
&& p.Name == "WorkflowName"
&&
(p.StatusCode.Value == 10 || // Waiting
p.StatusCode.Value == 20 || // In Process
p.StatusCode.Value == 0) // Waiting For Resources
select new AsyncOperation { Id = p.Id, StateCode = p.StateCode, StatusCode = p.StatusCode }).FirstOrDefault();
var fetchXml=@"<fetch mapping='logical' version='1.0'>
<entity name='asyncoperation'>
<attribute name='statecode' />
<attribute name='statuscode' />
<filter>
<condition attribute='asyncoperationid' operator='eq' value='{0}' />
</filter>
</entity>
</fetch>";
EntityCollection op = service.RetrieveMultiple(new FetchExpression(string.Format(fetchXml, processes.Id.ToString())));
if (op.Entities.Count == 1)
{
AsyncOperation o = op.Entities[0].ToEntity<AsyncOperation>();
o.StateCode = AsyncOperationState.Completed;
o.StatusCode = new OptionSetValue(32);
service.Update(o);
}
}
Even if i'm setting the StatusCode as 32 system is showing the workflow as succeeded. I just want to show the status as 'Cancelled'
Please help.