简体   繁体   English

在Dynamics 365 CRM上使用Xrm Object将表单设置为只读

[英]Set form read only using Xrm Object on Dynamics 365 CRM

I am reading about Xrm object on Microsoft Documentation but I can't find something concrete. 我在Microsoft文档上阅读有关Xrm对象的 信息,但是找不到具体的东西。

I need to restrict some roles of creating or editing a portal comment (type of activity ). 我需要限制创建或编辑门户网站注释活动类型)的某些角色。 Therefore I can't just simply modify security roles . 因此,我不能只是简单地修改安全角色

I see when I edit the portal comment form that there is a JavaScript script which executes on Page load: 我在编辑门户网站注释表单时看到,有一个JavaScript脚本可以在页面加载时执行:

页面加载脚本

When editing this it uses a lot this Xrm object. 编辑此对象时,它会Xrm大量Xrm对象。

In pseudocode I should do 用伪代码我应该做

if(ActiveUser.hasRoles(["Some role", "Some other role"]) {
    Page.setReadOnly(true);
}

I already have a script (as a web resource) to check the roles like this but I don't know how to make the form "read only" or make this with Xrm only. 我已经有一个脚本(作为网络资源)来检查这样的角色,但是我不知道如何将表单设置为“只读”或仅使用Xrm进行设置。 Any clues how to achieve this here? 任何线索如何在这里实现?

Edit 1: 编辑1:

I was able to do this by using the following code: 我可以通过使用以下代码来做到这一点:

// Ribbon "Save" button
document.querySelector('#crmRibbonManager').style.display = "none";
// Status "Save" button
document.querySelector('#savefooter_statuscontrol').style.display = "none";
Xrm.Page.ui.controls.get().forEach(function (control) {          
    if(!control.getDisabled()) {
        control.setDisabled(true);
    }
});

Of course I get Page Load error since the document is not loaded yet. 当然,由于文档尚未加载,我会收到页面加载错误 But I am pretty sure I could use some Xrm technique to disable these attributes, I have to study that. 但是我很确定我可以使用一些Xrm技术来禁用这些属性,我必须研究一下。

You are on right track. 您步入正轨。 Like you said, create/modify your js library web resource & register on form load rather than editing the existing OOB adx form scripting js file. 就像您说的那样,创建/修改js库Web资源并在加载表单时注册,而不是编辑现有的OOB adx表单脚本js文件。 In your js code - check the current user's security roles . 在您的js代码中-检查当前用户的安全角色

Xrm.Page.context.getUserRoles();

Then disable the fields in bulk . 然后批量禁用这些字段

Xrm.Page.getControl("myfield").setDisabled(true);

Dynamics 365 CRM platform has two forms namely Read-only & Disabled, former is loaded when user has only Read privilege for that particular entity & latter rendered for Inactive records. Dynamics 365 CRM平台有两种形式,即只读和禁用,前一种是在用户仅具有特定实体的读取特权时加载的,后者是为非活动记录呈现的。 Unfortunately we cannot force to load of any of these forms. 不幸的是,我们不能强迫加载任何这些形式。

To complement Arun's answer; 补充阿伦的答案;

This type of stuff is unsupported; 这种类型的东西不受支持; document.querySelector('#crmRibbonManager')

Microsoft Dynamics 365 and the importance of staying supported Microsoft Dynamics 365和保持支持的重要性

All JavaScript interactions within the application pages must only be performed using functions defined in Xrm.Page & Xrm.Utility namespaces, ie don't directly interact with the page DOM. 必须使用Xrm.Page和Xrm.Utility命名空间中定义的功能来执行应用程序页面内的所有JavaScript交互,即,不要直接与页面DOM交互。

If you want to control ribbon behaviours you should Customize commands and the ribbon , you will need to add an enable/display rule. 如果要控制功能区行为,则应该自定义命令和功能区 ,您将需要添加启用/显示规则。 Ribbon Workbench is a great tool for this. 丝带工作台是一个很好的工具。

Finally, it's worth nothing that this only controls client side validation. 最后,仅控制客户端验证毫无用处。 If you want server side rules the user can't avoid, you should look into implementing a plugin. 如果您想要用户无法避免的服务器端规则,则应考虑实施插件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 CRM Dynamics,如何使用一种形式传递值,并使用Xrm.Utility.openEntityForm()在新的Entity(form)中设置值; - CRM Dynamics , How to pass values from one form and set the values in a new Entity(form) using Xrm.Utility.openEntityForm(); 使用 JavaScript 为 CRM Dynamics 365 隐藏/删除选项设置值? - Hide/remove Option set value using JavaScript for CRM Dynamics 365? Dynamics CRM:在Eclipse中使用Xrm.Page库 - Dynamics CRM: using Xrm.Page library in Eclipse Dynamics CRM 365 - 无法访问HTML Web资源中的Xrm.Page.entity - Dynamics CRM 365 - Cannot access Xrm.Page.entity in HTML web ressource Dynamics CRM已读/未读表单 - Dynamics CRM Read/Unread Form 在 Dynamics 365 XRM Web API 中创建记录时无法设置多选选项字段 - Cannot set multi-select option field when creating record in Dynamics 365 XRM Web API 我想在Dynamics 365 crm中从一种形式重定向到另一种形式 - I want to redirect from one form to another in dynamics 365 crm Dynamics crm 365 快速创建表单获取父实体数据 - Dynamics crm 365 quick create form get parent entity data 在 Dynamics 365 CRM 统一界面中重新加载/刷新子网格时重新加载表单 - Reload Form on reload/refresh of subgrid in Dynamics 365 CRM Unified Interface 在 JS-Dynamics 365 中使用“Xrm.WebApi.createRecord”创建实体记录 - Create an Entity Record using "Xrm.WebApi.createRecord" in JS- Dynamics 365
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM