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.