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…


Author: Nishant Rana

I love working in and sharing everything about Microsoft.NET technology !

8 thoughts on “Calling form’s JavaScript functions in ISV.CONFIG”

    1. 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?

      Like

    1. 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 !!! 🙂

      Like

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

    Like

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s