ms crm app --> xpathevaluator' is undefined

Nov 13, 2015 at 12:05 PM

We are using crm 2015 and it is working without a problem. All code is executed correctly in IE and in Chrome. But when we try to use the crm app from Microsoft we get the error: 'xpathevaluator' is undefined. Can you help please?
Nov 17, 2015 at 11:02 AM
Could you elaborate a bit more?
Which XrmServiceToolkit function are you using when you get this error?

From my experience this message is an indicator that invalid xml was returned from the crm endpoint which the xrmservicetoolkit tries to interpret anyway by creating a new xpathevaluator object. Which in your case is not working as this is undefined.
Nov 19, 2015 at 7:22 AM
(Sorry for the late response, Was sick these last 2 days)

I think it fails on this function:

var selectSingleNode = function (node, xpathExpr) {
    if (typeof (node.selectSingleNode) != "undefined") {
        return node.selectSingleNode(xpathExpr);
    else {
        var xpe = new XPathEvaluator();
        var results = xpe.evaluate(xpathExpr, node, nsResolver, XPathResult.FIRST_ORDERED_NODE_TYPE, null);
        return results.singleNodeValue;

But I doubt the problem has anything to do with invalid xml as the issue only occurs when we use a tablet. Or the crm app in windows 8.1.
The web version works perfectly in different browsers.
Nov 19, 2015 at 7:46 AM
I know that this function is probably the one that is failing.
That's why I asked for a bit more information. Which method are you executing? For which entity?
The fact that "typeof (node.selectSingleNode) != "undefined" returns false indicates that node doesn't have a selectSingleNode function which implies that node is not an xml node and thus the response might not be valid xml.

Try finding out what node contains on the tablet. Or if you tell me which function has this issue, I can have a look as well to see if this happens for me as well.
Nov 19, 2015 at 8:53 AM
Edited Nov 19, 2015 at 8:53 AM
Ok, after some searching I found out it is on a custom fetch that we execute to retrieve the users security roles.
var fetchXml = "<fetch distinct='true' mapping='logical' output-format='xml-platform' version='1.0' >" +
                            "<entity name='systemuser' >" +
                                "<filter type='and' >" +
                                    "<condition attribute='systemuserid' operator='eq-userid' />" +
                                "</filter>" +
                                "<link-entity name='teammembership' intersect='true' visible='false' to='systemuserid' from='systemuserid' link-type='outer'>" +
                                    "<link-entity name='team' to='teamid' from='teamid' alias='ag' link-type='outer' >" +
                                        "<link-entity name='teamroles' intersect='true' visible='false' to='teamid' from='teamid' link-type='outer' >" +
                                            "<link-entity name='role' to='roleid' from='roleid' alias='teamroles' link-type='outer' >" +
                                                "<attribute name='name' />" +
                                            "</link-entity>" +
                                        "</link-entity>" +
                                    "</link-entity>" +
                                "</link-entity>" +
                                "<link-entity name='systemuserroles' from='systemuserid' to='systemuserid' link-type='outer' >" +
                                    "<link-entity name='role' from='roleid' to='roleid' alias='userroles' link-type='outer' >" +
                                        "<attribute name='name' />" +
                                    "</link-entity>" +
                                "</link-entity>" +
                            "</entity>" +

var fetchRes = XrmServiceToolkit.Soap.Fetch(fetchXml);
I believe that this is the line that gives the error.
But as I said this does work in the browser but not in the crm app in windows. According to my collegue this also isn't a problem on ios.
Nov 19, 2015 at 11:44 AM
I have been able to reproduce the error for me as well in the crm app on a windows 8.1 machine. (XrmServiceToolkit v 2.2)
Strange thing I noticed is that the fetch worked in an older version (2.0 beta) in the windows app.

Looking at the code for interpreting the responses between these versions, you can see they went from jQuery(xmlDoc).find to a more direct approach in using xml nodes and Xpath as a fallback.

I don't know if it's possible for you, but as a workaround you could try to do the following.
  • Download the 2.0 version of the XrmServiceToolkit
  • Add the 2.0 version to crm as a NEW web resource
  • On the form where you have this issue use this older version instead of the latest version
Make sure you don't include both versions on one form.
Also, be sure not to just replace the current version with the older one, because the newer version obviously has had some improvements which you might be using.
Marked as answer by bencap on 12/9/2015 at 11:49 PM
Dec 10, 2015 at 7:46 AM
Please check my question here:

It because crm app use IE 11