Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get UserId of current user in Custom Workflows of Microsoft Dynamics CRM 2011?

I need userId of current user in Custom Workflows of Microsoft Dynamics CRM 2011. So can you suggest me how to get it?

like image 755
Charan Raju C R Avatar asked Sep 07 '25 14:09

Charan Raju C R


1 Answers

Assuming that you are using c#, and that you created your custom workflow following Create a Custom Workflow Activity article from MSDN, it should inherit CodeActivity class, and has a method like:

protected override void Execute(CodeActivityContext context)
{
  // Your code here
}

To get the current userId, you need to obtain the IWorkflowContext from the CodeActivityContext, like this:

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

And then:

var id = workflowContext.UserId;
like image 139
Antoine Avatar answered Sep 10 '25 07:09

Antoine