Hi,
We had a requirement to check for user’s role on click of one of the isv.config button. So we thought of using JavaScript attribute of the button.
This is one of the very good article about how to use javascript for checking the roles
http://jianwang.blogspot.com/2008/01/crm-40-check-current-users-security.html
However using JavaScript within ISV.Config has its own share of trouble as it is an xml file, so we need to replace so many characters within it and moreover this has to be done very carefully.
So what we decided that we’d put the JavaScript code in the entity’s form’s onload event and would simply call that function within isv.config, than we wouldn’t have to replace characters within JavaScript for making them xml specific.
So suppose this is the JavaScript function
function UserHasRole(roleName)
{
//get Current User Roles, oXml is an object
var oXml = GetCurrentUserRoles();
if(oXml != null)
{
//select the node text
var roles = oXml.selectNodes("//BusinessEntity/q1:name");
if(roles != null)
{
for( i = 0; i < roles.length; i++)
{
if(roles[i].text == roleName)
{
//return true if user has this role
return true;
}
}
}
}
//otherwise return false
return false;
}
Now to make it reusable, so that we could call it within isv.config we just need to change its declaration
from
function UserHasRole(roleName)
{
// function body
}
to
UserHasRole=function(roleName)
{
// function body
}
and put it in the form’s onload event javascript.
And to call it within Button’s JavaScript –>
UserHasRole(‘System Administrator’)
Just like a normal function !!
Bye…
Posted in CRM, Microsoft Dynamics CRM Tagged: CRM, CRM 4.0

Like
Report
*This post is locked for comments