Asked by:
Indexof operation not working in IE8

Question
-
HI all,
Am using IE11, in Javascript am using Indexof() its working fine here, but its not working in IE8. Please find the code below. Request any one to fix it and alter this code and share it. Thanks in advance..
function Form_onload() {
var haystack_array = Xrm.Page.context.getUserRoles();
var i = haystack_array.indexOf('af259ead-ca7d-e311-b157-0050568074ef'); // Working fine in IE11 not in IE 8
alert(i);}
Thursday, March 13, 2014 12:14 PM
All replies
-
Hi Jerry,
IndexOf() isn't supported by IE8. Use the following code to make it work
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function (obj, start)
{
for (var i = (start || 0), j = this.length; i < j; i++)
{
if (this[i] === obj) { return i; }
}
return -1;
}
}
Admin QuikView Solution for CRM 2013
- Edited by Anupam Bishui Thursday, March 13, 2014 2:45 PM
- Proposed as answer by Anupam Bishui Friday, March 14, 2014 9:28 AM
Thursday, March 13, 2014 2:44 PM -
Hi Dynamotion,
How to use this code for my assigned value haystack_array.
Friday, March 14, 2014 2:22 AM -
I believe once you add the above code, your existing line of code should work as is. The above code provided by DynaMotion defines an IndexOf function for an Array which is missing in IE 8 and therefore it errors for you.
You need to include the function in your script library as a separate function.
Hope i have got this right
Sam
Dynamics CRM MVP | Inogic | http://inogic.blogspot.com| news at inogic dot com
If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
Friday, March 14, 2014 7:43 AM -
Hi Jerry,
Just copy paste this snippet in your code file, and there's nothing else you need to do. You indexOf() line will start working in IE8.
Friday, March 14, 2014 9:24 AM