Posted by: Nishant Rana | September 4, 2009

Calling form’s JavaScript functions in ISV.CONFIG

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…


Responses

  1. [...] is the original:  Calling form's JavaScript functions in ISV.CONFIG « Nishant Rana's … SHARETHIS.addEntry({ title: "Calling form's JavaScript functions in ISV.CONFIG « Nishant [...]

  2. 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

  3. But nishant, you didnt mention how to call javascript function from ISV’s button ?

    Can you please put it there ?

    • 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 !!! :)

  4. Thanks, I needed this.


Leave a response

Your response:

Categories