Dynamics CRM javascript 获得现场级安全性

Dynamics CRM javascript get field level security

在 JS 脚本中,使用 Web Api 我正在获取具有字段级安全性的特定实体字段的值。然后我想在网络资源中显示这个值。如何检测当前用户是否有权读取该特定字段?

仅当用户通过字段安全配置文件具有适当的读取权限时才会返回该值。因此,您不需要明确检查用户是否有权读取该字段。

来自Field level security to control access

The scope of field level security is organization-wide and applies to all data access requests including the following:

  • Data access requests from within a client application, such as web browser, mobile client, or Microsoft Dynamics 365 for Outlook.

  • Web service calls using the Dynamics 365 Customer Engagement Web Services (for use in plug-ins, custom workflow activities, and custom code)

  • Reporting (using Filtered Views)

从v9开始可以使用getUserPrivilege编辑:Guido在以前的CRM版本中也指出了这种方法availability)。

getUserPrivilege - Returns an object with three Boolean properties corresponding to privileges indicating if the user can create, read or update data values for an attribute. This function is intended for use when Field Level Security modifies a user’s privileges for a particular attribute

formContext.getAttribute(arg).getUserPrivilege()

这个returns canRead, canUpdate, canCreate 布尔值,因此你可以决定要做什么。

Reference

嗯,问题的原因很愚蠢:缓存的问题。第一次,我以管理员身份连接到 CRM,然后断开连接并以较少的权限登录,但由于 "power" 的缓存,我仍然能够查看 Web 资源中的字段。在私有 window 中查看表单时,字段级安全性在 Web 资源中起作用。但奇怪的是,在正常情况下 window 字段级安全性在表单中有效(字段值不可见)但在 Web 资源中不起作用。