I have a ribon rule to either show or hide the Deactivate button for accounts.
It's pretty straightforward
if (typeof (XTC) == "undefined")
{ XTC= { __namespace: true }; }
XTC.RibbonRules = (function () {
AccountRules = {
//see if user has roles specified to have the Deactivate button enabled.
IsDeactivateEnabled: function () {
var orgName = Xrm.Page.context.getOrgUniqueName();
var validGuids;
var allowedRoles = [];
/*
put all roles needed to show Account Deactivate button here.
*/
allowedRoles.push('System Administrator');
allowedRoles.push('XTC Admin');
var userRoles = Xrm.Page.context.getUserRoles();
//user has no assigned roles...
if (userRoles.length < 1)
return false;
var matchingRoles = AccountRules.returnMatchingRoles(userRoles);
for (var x = 0; x < matchingRoles.length; x++) {
if ($.inArray(matchingRoles[x].Name, allowedRoles) != -1)
return true;
}
return false;
},
returnMatchingRoles: function (roles) {
var matches;
var serverUrl = location.protocol + '//' + location.host + '/' + Xrm.Page.context.getOrgUniqueName();
var queryUrl = serverUrl + '/XRMServices/2011/OrganizationData.svc/' + 'RoleSet?$filter=';
for (var x = 0; x < roles.length; x++) {
if (x == roles.length - 1) {
queryUrl += "RoleId eq guid'" + roles[x] + "'";
}
else {
queryUrl += "RoleId eq guid'" + roles[x] + "' or ";
}
}
$.ajax({
url: queryUrl,
type: "GET",
async: false,
contentType: "application/json; charset=utf-8",
datatype: "json",
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest) {
matches = data.d;
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
alert('OData Select Failed: ' + textStatus + errorThrown + odataSelect);
}
});
return (matches.results.length > 0) ? matches.results : null;
}
};
return { AccountRules: AccountRules };
})();
So if the user doesn't have a role that's either of the two, the button is deactivated.
My issue is that this isn't running in the context of a form, so including web resources at form config is not working.
For some reason I can't figure out, from there, I have access to jQuery (2.1.1) but none of my other resources.
Is there a way to include web resources system wide so it may be available in this code, just like jQuery seems to be ?