Skip to main content
Unfortunately, portal is currently in readonly mode. You cannot post answers or questions.
Question
Asked a question 2 years ago

I'm trying to set a field to readonly based on security role. I'm trying to acheive it using Jscript, with the following code. But I'm getting the field readonly for every one or available for everyone. Please help function onLoad(executionContext) { debugger; if (executionContext != null) { var formContext = executionContext.getFormContext(); var formType = formContext.ui.getFormType(); var userSettings = Xrm.Utility.getGlobalContext().userSettings; var securityRoleList = userSettings.securityRoles; var userId = userSettings.userId; if (formType != 1 && formType != 2) { systemSecurityList(userId); } } } function systemSecurityList(Id) { debugger; var req = new XMLHttpRequest(); req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/systemuserrolescollection?$select=roleid,systemuserid&$filter=systemuserid eq "+Id+"&$orderby=roleid asc", true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var results = JSON.parse(this.response); for (var i = 0; i < results.value.length; i++) { var roleid = results.value[i]["roleid"]; var systemuserid = results.value[i]["systemuserid"]; var systemuserroleid = results.value[i]["systemuserroleid"]; if (roleid == "GUID") { Xrm.Page.ui.controls.get("customerid").setDisabled(false); } else Xrm.Page.ui.controls.get("customerid").setDisabled(true); } } else { Xrm.Utility.alertDialog(this.statusText); } } }; req.send(); }

Where am I?

In Dynamics Labs you can ask and answer questions and share your experience with others!

Related Questions

No related questions.