web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Get the current user inside a Workflow

Guido Preite Profile Picture Guido Preite 54,086 Moderator
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.

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));

}
}
}
After the Custom Activity is deployed using the Plugin Registration Tool, a new step is available

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



This was originally posted here.

Comments

*This post is locked for comments