Get the current user inside a Workflow
Views (3255)
Inside CRM 2011 Process editor it's not possible to get the current user, in some cases a reference can be necessary (specially for automated workflows) in order to set the right user when the workflow is used to create or assign records.
A Custom Workflow Activity can be created for this purpose, taking advantage of the InitiatingUserId property.

and the output parameter (Current User) can be used inside other steps

A Custom Workflow Activity can be created for this purpose, taking advantage of the InitiatingUserId property.
After the Custom Activity is deployed using the Plugin Registration Tool, a new step is available
using System;
using System.Activities;
using System.Collections.Generic;
using System.Runtime.Serialization;
using Microsoft.Xrm.Sdk;
using Microsoft.Xrm.Sdk.Workflow;
namespace WFUtils
{
public class GetCurrentUser : CodeActivity
{
[Output("Current User")]
[ReferenceTarget("systemuser")]
public OutArgument<EntityReference> CurrentUser { get; set; }
protected override void Execute(CodeActivityContext context)
{
IWorkflowContext workflowContext = context.GetExtension<IWorkflowContext>();
CurrentUser.Set(context, new EntityReference("systemuser", workflowContext.InitiatingUserId));
}
}
}

and the output parameter (Current User) can be used inside other steps

This was originally posted here.

Like
Report
*This post is locked for comments