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


1 comment:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.

    ReplyDelete

Popular Posts