Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

deactivating workflow using web api generates error

(0) ShareShare
ReportReport
Posted on by 195

I am trying to deactivate workflow (the definition workflow) I own using the web api, however, I get an error. The C# examples that I found suggest that this was all that was necessary to "publish/deactivate."

Thoughts?

web api payload:

{ "statecode": 0, "statuscode": 1 }

error:

{

"error": {
"code": "0x80045002",
"message": "Cannot update a published workflow definition.",
"innererror": {
"message": "Cannot update a published workflow definition.",
"type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",

...

}

*This post is locked for comments

  • aappddeevv Profile Picture
    195 on at
    RE: deactivating workflow using web api generates error

    There was mention that if you change the owner you can avoid xml messages and that's true but you don't always have that option.

  • aappddeevv Profile Picture
    195 on at
    RE: deactivating workflow using web api generates error

    That is correct. Yes, I consider it an omission/bug/feature. Hence, the original opening of this topic. I needed to confirm that no one else had made this work yet and there was a way around it.

  • Community Member Profile Picture
    on at
    RE: deactivating workflow using web api generates error

    Mr. Aappddeevv,

    Your solution is also based on the Organization service. It is calling the SetStateRequest which has no equivalent in the Web Api. If my understanding is correct we should be able to do that by calling the PATCH verb but it is not working specifically for the Workflow entity. I was able to do that on other entities so I am pretty sure there is a bug for Workflow.

  • aappddeevv Profile Picture
    195 on at
    RE: deactivating workflow using web api generates error

    You have to use the organization service to change activation status, but the nice thing is that once logged in for the Web API you can use the web service message (SOAP) directly. That's what I did.

    github.com/.../workflows.scala

    Maybe things have change with the most recent API update though. I've not checked.

  • Community Member Profile Picture
    on at
    RE: deactivating workflow using web api generates error

    Adrian, thanks for the quick feedback.

    Unfortunately, the solution you suggest is using the Organization service. I am trying to achieve the same thing but using the Web Api.

  • Suggested answer
    Adrian Begovich Profile Picture
    1,019 Super User 2025 Season 1 on at
    RE: deactivating workflow using web api generates error

    Hi,

    You may find this article helpful.

  • Community Member Profile Picture
    on at
    RE: deactivating workflow using web api generates error

    Can you provide more detail on how you were able to update StateCode and StatusCode on workflows ?

    I always get the following error :

    {
    	"error": {
    		"code": "0x80045002",
    		"message": "Cannot update a published workflow definition.",
    		"innererror": {
    			"message": "Cannot update a published workflow definition.",
    			"type": "System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=9.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]",
    			"stacktrace": "   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext, Dictionary`2 optionalParameters)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Upsert(Entity entity)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataExecutionContext.Update(Entity entity, UpdateOption updateOption)\r\n   at Microsoft.Crm.Extensibility.OData.CrmODataServiceDataProvider.UpdateEdmEntity(CrmODataExecutionContext context, String edmEntityName, String entityKeyValue, EdmEntityObject entityObject)\r\n   at Microsoft.Crm.Extensibility.OData.EntityController.PatchEntityImplementation(String& entityName, String key, EdmEntityObject entityDelta)\r\n   at Microsoft.PowerApps.CoreFramework.ActivityLoggerExtensions.Execute[TResult](ILogger logger, EventId eventId, ActivityType activityType, Func`1 func, IEnumerable`1 additionalCustomProperties)\r\n   at Microsoft.Xrm.Telemetry.XrmTelemetryExtensions.Execute[TResult](ILogger logger, XrmTelemetryActivityType activityType, Func`1 func)\r\n   at lambda_method(Closure , Object , Object[] )\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ActionExecutor.<>c__DisplayClass10.<GetExecutor>b__9(Object instance, Object[] methodParameters)\r\n   at System.Web.Http.Controllers.ReflectedHttpActionDescriptor.ExecuteAsync(HttpControllerContext controllerContext, IDictionary`2 arguments, CancellationToken cancellationToken)\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ApiControllerActionInvoker.<InvokeActionAsyncCore>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__1.MoveNext()"
    		}
    	}
    }


    Here is my request :

    PATCH myorg.crm.dynamics.com/.../workflows(79cbac5f-1ab7-e611-80d9-000d3a11dc39) HTTP/1.1
    OData-MaxVersion: 4.0
    OData-Version: 4.0
    Content-Type: application/json
    
    {
      "statecode": 0,
      "statuscode": 1
    }


  • aappddeevv Profile Picture
    195 on at
    RE: deactivating workflow using web api generates error

    I should add that deactivating via the web api works using the payload as described above with adjusted values.

  • aappddeevv Profile Picture
    195 on at
    RE: deactivating workflow using web api generates error

    I saw that sample. It is indicated that the SetState request should migrate to UpdateRequest which is what I thought the web api was doing as a POST.

    https://msdn.microsoft.com/en-us/library/microsoft.crm.sdk.messages.setstaterequest.aspx.

  • Shaminderpal Singh Profile Picture
    1,565 on at
    RE: deactivating workflow using web api generates error

    Hi

    It seems simple update request wont deactivate it.

    We need to do a set state request as per below:

    msdn.microsoft.com/.../jj602950.aspx

    I also checked whether we have any web api function equivalent to that but it seems there isn't any

    msdn.microsoft.com/.../mt607866.aspx

    Regards,

    Shaminder

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

Daivat Vartak – Community Spotlight

We are honored to recognize Daivat Vartak as our March 2025 Community…

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Kudos to the February Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,863 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 231,723 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156 Moderator

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans