I am firing the following code on a form load even for a CRM entity form. When doing so, depending on the user I get a runtime error. I'm hoping someone might know what permission or other issues might be causing this. The error is very generic and looks to be throw from CRM and not my code, nor a plugin, but the JavaScript itself. Here's the error...
"An error occurred. Please wait a few moments and try again. If the problem persists, contact a system administrator."
When I run it as an admin, it works fine. When I run it as one type of user it works fine as well. But when I run it as one of our other user types, they get a runtime error. What could be unique about that one user type that might cause a runtime error. Are their specific permissions that have to be set to allow the following code to function?
Interestingly, even when we get the error, the code seems to have ran correctly and completed. So maybe the JavaScript is not where the error is occurring. In the plugins, I have logging and custom errors and none of those get reached. So I don't think this is firing from a plugin. I suspect it is the JavaScript code itself.
What this is doing is identifying some temporary Accounts we used in our business process. For those, I don't want the user to be able to modify them name, type, or account number. So to mark these I tag them as DUMMY accounts in the account number. So the JavaScript just verifies if the tag is there in the account number and if so, sets the fields to read only. Why would one particular user type not be able to execute this sort of code?
Best regards,
Jon
SetReadOnlyForDummyAccounts = function () { var readOnly = false; try { var accountNumber = Xrm.Page.getAttribute("accountnumber").getValue(); if (accountNumber != null) { var index = accountNumber.indexOf("DUMMY"); if (index >= 0) { readOnly = true; } } } catch (err) { alert('Error:' + err ); } SetReadOnly("name", readOnly); SetReadOnly("customertypecode", readOnly); SetReadOnly("accountnumber", readOnly); }
I have a library with a few helper functions. Here's the SetReadyOnly() function.
function SetReadOnly(fieldName, isReadOnly) { Xrm.Page.getControl(fieldName).setDisabled(isReadOnly); }
Jon Gregory Rothlander