Quantcast
Channel: C5 Insight Blogs - Business Strategy, SharePoint, Dynamics CRM, Salesforce.com, Collaboration and Relationship Management - Technical
Viewing all articles
Browse latest Browse all 28

Dynamics CRM Versions and Array Method “indexOf”

$
0
0

For one of my recent projects there was a requirement where I had to check the logged in user’s security roles, to find out if the user had been assigned a particular security role. If the user had the security role, there were several JavaScripts that would run. If the user did not have the security role, the JavaScript would not run.

To get the user’s security roles, I used an OData query. After getting the results from the OData query, I saved those results into an array. In order to get the required security role from the array of security roles, I parsed the array of security roles by using the array method “IndexOf”.

userHasRole = userRole.indexOf("Role Name");

To create the code, I used a test Dynamics CRM 2015 online organization. I added a web resource to the OnLoad event of the record and I received the result shown below.

 

   http://blogs.c5insight.com/Portals/0/SunBlogNuke/1/Windows-Live-Writer/3ca7a641f7ba_B70A/image_2.png

 

But when I added this code into Dynamics CRM 2011 I received the error shown below:

“There was an error with this field's customized event. Error: Object doesn't support this property or method."

     image_thumb[1]


I started debugging and found out that the line “userHasRole = userRole.indexOf("Role Name");”, was causing the error. Returning to my test environment, I verified my code still worked in Dynamics CRM 2015 and also verified it worked in Dynamics CRM 2013. I could not figure out why it was working in these and not in the CRM 2011 environment.

Next I checked my browser settings, Internet explorer version, and everything looked fine. I tried using another browser as well but received the same error that was received in the first browser.

Then I decided to use a different approach instead of “indexOf” to parse my security roles.


1 var RoleName = "Please put your role name here"; 2 3 4 // Check for security role by looping through array 5 for (var i in userRole) 6 { 7 if (userRole[i] == RoleName) 8 {alert(userRoleName); 9 } 10 }

Once I used this array parsing method in my JavaScript code it started working fine. Turns out the indexOf method is a JavaScript 1.6 feature and it is supported in the following browsers:

  • IE9+
  • Firefox 1.5+
  • Chrome
  • Safari
  • Opera

Even though we did not figure out exactly why indexOf did not work in the CRM 2011 environment we were working in, we were able to substitute a different method to get the needed result. Hopefully this will help someone who is having the same issue.

For more information about this blog or C5 Insight, contact us here!

 


Viewing all articles
Browse latest Browse all 28

Latest Images

Trending Articles





Latest Images