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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Dynamics 2011 JSON is undefined on one server but not on another

(0) ShareShare
ReportReport
Posted on by

Hello 

I'm having an unusual issue here.

We have two environments, one for development and the live environment that is used everyday. Both on different servers.

I assume that both were implemented the exact same way. I wasn't part of the implementation.

The thing is, I'm using window.parent.JSON.parse() to parse the result of a odataselect, but the code is not working on the live environment.

On the development environment is working great.

The error I'm getting is JSON is undefined.

My main question here is why it works on the DEV environment and not on the live one.

Here is the code (is inside a html web resource):

function ODataSelect(entity, fields, filter, order, useasync, multi) 
	{
        /// Funcion generica para hacer selects con OData
        /// <entity>: Nombre de entidad, sin "Set"
        /// <fields>: campos, separados por coma
        /// <filter>: filtro con sintaxis de OData
        /// <order>: (opcional) Orden del query
        /// <useasync>: (opcional) Usa llamadas asincronicas
        /// <multi>: (opcional) Devuelve multiples registros (por defecto desactivado)
		//debugger;
        var retVal;
        var organizationName = window.parent.Xrm.Page.context.getOrgUniqueName();
        var serverURL = window.location.protocol + "//" + window.location.hostname + ":" + window.location.port + "/" + organizationName;
        var consulta = serverURL + "/xrmservices/2011/OrganizationData.svc/" + entity + "Set?";
        consulta += "$select=" + fields + "&";
        if (order != undefined) {
            consulta += "$orderby=" + order + "&";
        }

        if (filter != undefined) {
            consulta += "$filter=" + filter;
        }
		
        if (useasync === undefined) {
            useasync = false;
        }

        if (multi === undefined) {
            multiples = false;
        } else {
            multiples = multi;
        }

        var retrieveReq = new XMLHttpRequest();
        retrieveReq.open("GET", consulta, false);
        retrieveReq.setRequestHeader("Accept", "application/json");
        retrieveReq.setRequestHeader("Content-Type", "application/json; charset=utf-8");
        retrieveReq.send();
		
		var respuesta = retrieveReq.responseText;
		
        var retrieved = window.parent.JSON.parse(respuesta);
		retrieved = JSON.parse(respuesta);
		//retrieved = this.json_parse(respuesta);
		
        if (retrieved.d.results.length == 0) {
            return;
        }
        if (multiples) {
            retVal = retrieved.d.results;
        } else {
            retVal = retrieved.d.results[0];
        } 
       
        return retVal;
    }


I would like to know why is not working.

But as an alternative solution I tried to add json2.js as a web resource, and add the reference in the code using relative paths, but it is not working ether.

*This post is locked for comments

I have the same question (0)
  • Community Member Profile Picture
    on at

    Hi Matias

    I observe this problem when the address for live environment is https and dev is http.

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans