如何在CRM插件中获取当前用户记录? [英] How to get current user record in CRM plugin?

查看:74
本文介绍了如何在CRM插件中获取当前用户记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发插件。每当调用插件时,我都需要获取当前的用户信息?有什么方法可以找回它?

I am developing a plugin . Whenever a plugin gets invoked, I need to get current user information ? Is there any way to retrieve that?

推荐答案

该信息可在PluginExecutionContext中获得。下面的代码来自您的插件必须实现的Execute方法。

The information is available in the PluginExecutionContext. The code below is from the Execute method your plugin must implement.

public void Execute(IServiceProvider serviceProvider)
{
    IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
        IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    Guid userId = context.InitiatingUserId;
}

仅供参考,该上下文还具有 UserId属性,该属性可能会或可能不会与InitiatingUserId相同。如果您的插件步骤注册在用户上下文中运行字段的值为呼叫用户,则它们将相同。如果您在在用户上下文中运行字段中指定了用户,则UserId字段将包含您指定的人的用户ID,而InitiatingUserId将是其操作触发了插件的实际CRM用户。听起来好像您在寻找InitiatingUserId。

FYI, the context also has a "UserId" property that may or may not be the same as the InitiatingUserId. If your plugin step registration "Run in Users's Context" field has the value "Calling User", then they will be the same. If you have specified a user in the "Run in User's Context" field, then the UserId field will contain the user ID of the person you specify and the InitiatingUserId will be the actual CRM user whose action triggered the plugin. Sounds like you're looking for the InitiatingUserId.

这篇关于如何在CRM插件中获取当前用户记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆