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
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
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:)
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.
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
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
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
André Arnaud de Cal... 291,711 Super User 2024 Season 2
Martin Dráb 230,458 Most Valuable Professional
nmaenpaa 101,156