How to update the Dynamics 365 workflow triggering update attributes list using C# Code CRM SDK ?

Subject: How to update the Dynamics 365 workflow triggering update attributes list using C# Code CRM SDK ?

Hello Everyone,

I got one strange requirement in my life in Dynamics CRM Project and we would like to share my knowledge with you people.

Requirement: 

Workflow on opportunity and it should trigger on update of fields like customer,total revenue.... but these triggering fields needs to configurable and actual users they don't want to deactivate workflow and activate every time.


Solution: 

we have developed the following piece of code in Plugin

           QueryExpression query = new QueryExpression("workflow");
            query.ColumnSet.AllColumns = true;
            query.Criteria.AddCondition("name", ConditionOperator.Equal, "Test workflow"); // Pass your workflow name
            EntityCollection ec = service.RetrieveMultiple(query);
           

            SetStateRequest deactivateRequest = new SetStateRequest
            {
                EntityMoniker =
                         new EntityReference("workflow", ec.Entities[0].Id),
                State = new OptionSetValue(0),
                Status = new OptionSetValue(1)
            };

            service.Execute(deactivateRequest);
            Entity e = new Entity("workflow");
            e.Attributes["triggeronupdateattributelist"] = "name,customer"; 
               // Pass your triggering fields as comma separated.
            e.Id = ec.Entities[0].Id;
            service.Update(e);

            SetStateRequest activateRequest = new SetStateRequest
            {
                EntityMoniker =
                        new EntityReference("workflow", ec.Entities[0].Id),
                State = new OptionSetValue(1),
                Status = new OptionSetValue(2),


            };
            service.Execute(activateRequest);



Previous Links:

CRMOnce: Dynamics 365 CRM Training Course Content - Hyderabad,Chennai,Banglore,Pune


2 comments:

  1. Operating from home can certainly be called telecommuting, which suggests working from an isolated location which often refers to the home office. remote work templates

    ReplyDelete
  2. I found your this post while searching for information about blog-related research ... It's a good post .. keep posting and updating information. https://europa-road.eu/hu/magas-szinvonalu-gepszallitas-budapest.php

    ReplyDelete

Popular Posts