Thanks for your help on this, so far I have created a HTML webresource, added it to the Account entity but its not working, here is the code:
<HTML><HEAD><TITLE>Opportunity Header</TITLE>
<SCRIPT src="a_crmsystem/.../jquery1.4.1.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="../WebResources/ClientGlobalContext.js.aspx"></SCRIPT>
<SCRIPT language=javascript>
function PostalSearchClick()
{
var baseFetch = '<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"><entity name="a_citybypostalcode"><attribute name="a_citybypostalcodeid" /><attribute name="a_Street1" /><attribute name="a_Street2"/><attribute name="a_Street3" /><attribute name="a_postalcode" /><attribute name="a_country" /><attribute name="a_city" /><order attribute="a_Street3" descending="false" /><entity></fetch>';
var postalCondition = "";
var postalValue = $('#SrcCriteria').val();
if (postalValue != -1)
{
//postalValue = postalValue.replaceAll("*", "%");
postalCondition = '<condition attribute="a_postalcode" operator="eq" value="' + postalValue +'" />';
}
var filterFetch = postalCondition;
var rawFetch = baseFetch.replace("{FILTER}", filterFetch)
var fetch = encodeURI(rawFetch);
var queryPath = "/api/data/v8.0/a_citybypostalcode?fetchXml=" + fetch;
var req = new XMLHttpRequest();
req.open("GET", parent.Xrm.Page.context.getClientUrl() + queryPath, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.maxpagesize=5000");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var results = JSON.parse(this.responseText);
//console.log(results);
if (results)
{
alert("Results");
//process your results...
}
{
alert("No Results");
}
}
else
{
alert(this.statusText);
}
}
};
req.send();
}
</SCRIPT>
<META charset=utf-8></HEAD>
<BODY contentEditable=true><INPUT id=SrcCriteria maxLength=20 name=SrcCriteria></INPUT> <INPUT onclick=PostalSearchClick(); id=btn_Src type=button value=Search></INPUT></BODY></HTML>
It all appears to work down to req and it then does nothing so I am assuming it is crashing out - what is the best way to error trap this?
This is on CRM 2011 RU 11, just for info.
Regards,
Matt