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…
Discover more from Nishant Rana's Weblog
Subscribe to get the latest posts sent to your email.

Hi Nishant Rana
i am so sorry to post this here and sorry to trouble you.
I am Zhongchen Zhou from China and I am currently in Australia and working on MS Dynamics CRM 4 in an company called QA Software, and I am planning to take certification exams. I read your post and I am wondering that Can you please send me eBooks.
Thanks for your sharing and i will really appreciate it
zzhou@qa-software.com
Thanks again
LikeLike
But nishant, you didnt mention how to call javascript function from ISV’s button ?
Can you please put it there ?
LikeLike
Hi Viral,
If the function is declared\defined in this manner in form load
UserHasRole=function(roleName)
{
// function body
}
Than you could call the function within the isv.config button for that form, the way you would call a normal function like
UserHasRole();
I hope i am clear this time !!! 🙂
LikeLike
Thanks, I needed this.
LikeLike
This helps if the buttons are in the form. But if the buttons are in the main window, it will not have onload/onsave methods. So we have to write them in ISV.Config iteslf.
Any alternatives?
LikeLike
you are registering the button on an entity and that onload event will be connected to the button I think…
LikeLike
scruffy neutralise liverish Charly raksanyi enslavement kathrine Carmel ragtime
LikeLike