web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Workflow error when cancelling the task

(0) ShareShare
ReportReport
Posted on by 1,160

Hi Experts,

I'm getting the following error when I'm trying to cancel a workflow through coded workflow activity.

"The state transition requested is not valid for the current state. Current state: 3, current status: 32, target state: 3."

Please see the code below which i'm using to cancel the workflow.

var processId = (from p in serviceContext.AsyncOperationSet
where
p.PrimaryEntityType.Equals(entityName) &&
p.RegardingObjectId.Id.Equals(entityId) &&
p.Name.Equals(workflowName) &&
(
p.StatusCode.Value == 10 || // Waiting
p.StatusCode.Value == 20 || // In Process
p.StatusCode.Value == 0 // Waiting For Resources
)
select p.Id).FirstOrDefault();


Entity workflow = new Entity("asyncoperation");

workflow.Id = processId;
workflow["statecode"] = new OptionSetValue(3);
workflow["statuscode"] = new OptionSetValue(32);

service.Update(workflow);

thanks

Anil

*This post is locked for comments

I have the same question (0)
  • Rajkumar Rajaraman Profile Picture
    on at
    RE: Workflow error when cancelling the task

    Anil,

    Refer this blog:

    community.dynamics.com/.../crm-2011-how-to-cancel-terminate-workflow-programmatically-using-c

    Hope this helps.

    Regards,

    R.Rajkumar

    "Please mark my answer as verified if you found it helpful"

  • anilambadan Profile Picture
    1,160 on at
    RE: Workflow error when cancelling the task

    The link you provided will not help me. I'm using same type of logic and its throwing the error.  Im just looking for an answer why its happening? 99% occasions its working fine without any errors.

  • Rajkumar Rajaraman Profile Picture
    on at
    RE: Workflow error when cancelling the task

    Have you referred this thread?

    community.dynamics.com/.../157381

  • anilambadan Profile Picture
    1,160 on at
    RE: Workflow error when cancelling the task

    Thank you, I'll check it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
HR-09070029-0 Profile Picture

HR-09070029-0 2

#2
ED-30091530-0 Profile Picture

ED-30091530-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans