web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

undefined is not a constructor evaluating new XMLHttpRequest

(0) ShareShare
ReportReport
Posted on by 352

Hi, for a project with Dynamics 365 Online version 8.2, I wrote a JS script which runs on the Order Entity,  performs a web api query and uses a call to XMLHttpRequest using this pretty straightforward piece of code:

var finalFetchXML = String.Format(query,entityGUID)
var encodedFetchXML = encodeURIComponent(finalFetchXML);
var queryPath = "/api/data/v8.0/salesorderdetails?fetchXml=" + encodedFetchXML;
var requestPath = Xrm.Page.context.getClientUrl() + queryPath;

var req = new XMLHttpRequest();
req.open("GET", requestPath, true);

It works fine in a regular browser but when I use the phone app in iOS (latest version) I found a weird behavior.

  • If I go the any order record and press the refresh option in the phone app I got the following error:

Event: listLoad

Error: undefined is not a constructor (evaluating new XMLHttpRequest())

  • If I never press the refresh option in the phone app, the call is made (asynchronously) and a field is updated in the form (after accepting the save prompts).

I would like to understand the reason behind this behavior with the refresh option and as always, any advise from you is much appreciated.

Xavier

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Syed Ibrahim Profile Picture
    6,257 on at
    RE: undefined is not a constructor evaluating new XMLHttpRequest

    Hi Xavier,

    Did you include the the below check on the js as first step?

    if (Xrm.Page.context.client.getClient() == "Mobile")

    If not pls add the check and see.

    Hope this helps.If the suggestion resolved your query .Pls mark it as answered/verified to close the thread.

  • Xavier Villafuerte Profile Picture
    352 on at
    RE: undefined is not a constructor evaluating new XMLHttpRequest

    Hi Syed. Well, as far as I understand, the conditional sentence you mention applies only if you want to specify code to be run on an specific type of client, In this case mobile. However, I need to run the web api query in all the Clients and Because of that, I am not using it in my code. Please let me know if I am wrong in any way.

  • Suggested answer
    Community Member Profile Picture
    on at
    RE: undefined is not a constructor evaluating new XMLHttpRequest

    Hi Xavier,

    if seems the client has not still loaded XMLHttpRequest .

    Try to incapsuate your call in a setInterval method, like this:

    var loadInterval = setInterval(function(){ 

    if(!XMLHttpRequest) return;

    clearInterval(loadInterval);

    // yourcode
    ...

    }, 3000);

    Please let me know if you solve.

    If you found the answer helpful, please mark as Verified 

    Join my network on LinkedIn      Follow me on Twitter 

    Thank You & Best Regards

    Francesco Picchi

    Microsoft Dynamics CRM Consultant, Bologna+Milano, ITALY

    Independent Contractor

    http://www.francescopicchi.com

  • Suggested answer
    Xavier Villafuerte Profile Picture
    352 on at
    RE: undefined is not a constructor evaluating new XMLHttpRequest

    Thanks Francesco for your response. It did not work as expected. However I found the solution implementing the call for a new instance of XMLHttpRequest using this code:

    function getXHR(){

    if(window.XMLHttpRequest){

     return new XMLHttpRequest()

    }

    else try {

     return new ActiveXObject('Msxml2.XMLHTTP')

    } catch (e) {

      try{

        return new ActiveXObject("Microsoft.XMLHTTP")

         } catch(e) {

        return null

     }

    }

    }

    Then, I call the getXHR function in my main script as follows:

    var req = getXHR()

    if (req != null) {

    --my code

    }

    I test it with my original scenario (browser and mobile app) and I have no more errors anymore. As a reference I found the code above in this link:

    books.google.com.ec/books;pg=PA151&lpg=PA151&dq=if(XMLHttpRequest)+mobile&source=bl&ots=Va3APYl_5o&sig=S6prjBJarfKrYiUt9nz1iEfd_5o&hl=es&sa=X&ved=0ahUKEwjSnrKthLjYAhVB6SYKHRU3D_UQ6AEIaDAI#v=onepage&q=if(XMLHttpRequest)%20mobile&f=true

    I hope it helps

    Xavier

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
UllrSki Profile Picture

UllrSki 2

#3
SC-08081331-0 Profile Picture

SC-08081331-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans