准备代码
//获取当前登录者权限信息,设置字段可见性
function Field_Display() {
var rolesID = Xrm.Page.context.getUserRoles();//获取当前用户的权限id
for (var i = 0; i < rolesID.length; i++) {//一个用户可以拥有多个安全角色
var Url = Xrm.Page.context.getClientUrl() + "/api/data/v9.0/roles(" + rolesID[i] + ")?$select=name";
var data_name = "";
$.ajax({
url: Url,
type: "get",
async: false,
headers: {
"Content-Type": "application/json; charset=utf-8",
"Accept": "application/json",
"OData-MaxVersion": "4.0",
"OData-Version": "4.0"
},
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
data_name = data;
}
})
if (data_name["name"] != "系统管理员") {
Xrm.Page.getControl("new_adas").setVisible(false);//除了管理员其他权限都见不到
}
}
}