Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Updating BPF in workflow

(0) ShareShare
ReportReport
Posted on by 1,299

Hi,

Is there any way we can update BPF using Workflow, i have created a workflow in opportunity but i am not getting the BPF in the workflow "Update" step of the workflow.

Thanks.

*This post is locked for comments

  • Suggested answer
    Preeti Sharma Profile Picture
    Preeti Sharma 2,678 on at
    RE: Updating BPF in workflow

    Hi,

    I have worked once with updating business process flow using workflow. Code for that is as follows:

    // <copyright file="ProcessWorkflow.cs" company="">

    // Copyright (c) 2017 All Rights Reserved

    // </copyright>

    // <author></author>

    // <date>2/3/2017 9:47:38 AM</date>

    // <summary>Implements the ProcessWorkflow Workflow Activity.</summary>

    namespace BusinessProcessWorkflow

    {

       using System;

       using System.Activities;

       using System.ServiceModel;

       using Microsoft.Xrm.Sdk;

       using Microsoft.Xrm.Sdk.Workflow;

       using Microsoft.Xrm.Sdk.Client;

       using System.Linq;

       using Microsoft.Xrm.Sdk.Query;

       public sealed class ProcessWorkflow : CodeActivity

       {

           /// <summary>

           /// Executes the workflow activity.

           /// </summary>

           /// <param name="executionContext">The execution context.</param>

           /// [RequiredArgument]

           [Input("Process Name")]

           public InArgument<string> Process { get; set; }

           [RequiredArgument]

           [Input("Process Stage Name")]

           public InArgument<string> ProcessStage { get; set; }

           protected override void Execute(CodeActivityContext executionContext)

           {

               // Create the tracing service

               ITracingService tracingService = executionContext.GetExtension<ITracingService>();

               if (tracingService == null)

               {

                   throw new InvalidPluginExecutionException("Failed to retrieve tracing service.");

               }

               tracingService.Trace("Entered ProcessWorkflow.Execute(), Activity Instance Id: {0}, Workflow Instance Id: {1}",

                   executionContext.ActivityInstanceId,

                   executionContext.WorkflowInstanceId);

               // Create the context

               IWorkflowContext context = executionContext.GetExtension<IWorkflowContext>();

               if (context == null)

               {

                   throw new InvalidPluginExecutionException("Failed to retrieve workflow context.");

               }

               tracingService.Trace("ProcessWorkflow.Execute(), Correlation Id: {0}, Initiating User: {1}",

                   context.CorrelationId,

                   context.InitiatingUserId);

               IOrganizationServiceFactory serviceFactory = executionContext.GetExtension<IOrganizationServiceFactory>();

               IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

               try

               {

                    // Get the processid using the name provided

                       var processName = Process.Get<string>(executionContext);

                       string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>

                                             <entity name='workflow'>

                                               <attribute name='workflowid' />

                                               <attribute name='name' />

                                               <attribute name='category' />

                                               <attribute name='primaryentity' />

                                               <attribute name='statecode' />

                                               <attribute name='createdon' />

                                               <attribute name='ownerid' />

                                               <attribute name='owningbusinessunit' />

                                               <attribute name='type' />

                                               <order attribute='name' descending='false' />

                                               <filter type='and'>

                                                 <condition attribute='businessprocesstype' operator='eq' value='0' />

                                                 <condition attribute='name' operator='eq' value='" + processName + @"' />

                                               </filter>

                                             </entity>

                                           </fetch>";

                       EntityCollection processreturned = service.RetrieveMultiple(new FetchExpression(fetchXml));

                     //  throw new Exception(processreturned.Entities.Count.ToString());

                       if (processreturned.Entities.Count > 0)

                       {

                           Entity process = processreturned.Entities[0];

                           if (process == null)

                               throw new InvalidPluginExecutionException(String.Format("Process '{0}' not found", Process.Get(executionContext)));

                           var stageName = ProcessStage.Get<string>(executionContext);

                           string fetchStage = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='true'>

                             <entity name='processstage'>

                               <attribute name='processstageid' />

                               <attribute name='processid' />

                               <filter type='and'>

                                   <condition attribute='stagename' operator='eq' value='" + stageName + @"' />

                                   <condition attribute='processid' operator='eq' value='" + process.Id + @"' />

                                 </filter>

                            </entity>

                           </fetch>";

                           EntityCollection processStagereturned = service.RetrieveMultiple(new FetchExpression(fetchStage));

                           if (processStagereturned.Entities.Count > 0)

                           {

                               Entity stage = processStagereturned.Entities[0];

                               // Change the stage

                               Entity updatedStage = new Entity(context.PrimaryEntityName);

                               updatedStage.Id = context.PrimaryEntityId;

                               updatedStage["stageid"] = stage.Id;

                               updatedStage["processid"] = process.Id;

                               service.Update(updatedStage);

                           }

                       }

               }

               catch (FaultException<OrganizationServiceFault> e)

               {

                   tracingService.Trace("Exception: {0}", e.ToString());

                   // Handle the exception.

                   throw;

               }

               tracingService.Trace("Exiting ProcessWorkflow.Execute(), Correlation Id: {0}", context.CorrelationId);

           }

       }

    }

    Hope this helps:)

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Updating BPF in workflow

    Davy,

    Create the workflow that advances on the BPF itself, or create a relationship between the process and the entity itself. 

    If you need more specific information, hit me up at jesse.e.lott@outlook.com , didn't want to insult your intelligence by being too in-depth.  I'm sure you can figure it out with this guidance.

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: Updating BPF in workflow

    Give it a try

    www.summitgroupsoftware.com/.../how-update-stage-field-through-workflow

    if this doesnt work, there's nothing OOB, you will have to use a javascript

  • Davyjones Profile Picture
    Davyjones 1,299 on at
    RE: Updating BPF in workflow

    Thanks Prashant,

    Whenever there is a something related to BPF you are there, is there something OOB that i can use other than this solution?

    Thanks again

  • Suggested answer
    PS Profile Picture
    PS 23,577 on at
    RE: Updating BPF in workflow

    Hi Davyjones,

    Try this solution, if it helps: www.crmug.com/.../advancing-business-process-flows-via-workflow

    Ctrl+f and find 'here' click to download

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

Congratulations 2024 Spotlight Honorees

Kudos to all of our 2024 community stars! 🎉

Meet the Top 10 leaders for December

Congratulations to our December super stars! 🥳

Start Your Super User Journey

Join the ranks of our community heros! 🦹

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,711 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,458 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans