Hello,
I am trying to build a custom CRM button that will pop open a map that displays all selected Accounts. I have the button and I have the mapping working for a certain amount of accounts. My issue is that somewhere between the array of accounts (this includes name, address, lat, longitude, etc.) and using JSON.stringify(MYARRAY) the string gets truncated (4000 characters including the additions made by encodeURIComponent). So if I pick 30 accounts to plot I only get 4000 characters worth of points plotted (12-15). Below is my code, I hope someone can help me. This is using Javascript. This is an onclick event from the Account homepage. I am not having trouble getting data from my records, just passing it into my HTML (not included), I have bolded the troubled portion.
function run(selectedItems) { //pass user GUID
var AddressAray = new Array();
debugger;
for (i = 0; i < selectedItems.length; i++)
{
var selectedItem = selectedItems[i].Id;
RetrvAddress(selectedItem, "accounts", "address1_composite,name,address1_longitude,address1_latitude,dds_finance_bucket,_primarycontactid_value", "primarycontactid($select=fullname)",
function (result) {
AddressAray.push(MixedFields);
},
function (error) {
alert('GetCurrentUserTerritory: ' + error.message);
},
false);
}
var customParameters = encodeURIComponent(JSON.stringify(AddressAray));
Xrm.Utility.openWebResource("../WebResources/ddscrm_/webpages/CRMPRD.XRM.GoogleMaps.html",customParameters);
}
var RetrvAddress = function (id, type, select, expand, successCallback, errorCallback, async) {
var systemQueryOptions = "";
if (select != null || expand != null) {
systemQueryOptions = "?";
if (select != null) {
var selectString = "$select=" + select;
if (expand != null) {
selectString = selectString + "&$expand=" + expand;
}
systemQueryOptions = systemQueryOptions + selectString;
}
else if (expand != null && select == null) {
systemQueryOptions = systemQueryOptions + "$expand=" + expand;
}
}
MyGUID= id;
var clientUrl = Xrm.Page.context.getClientUrl();
var oDataPath = clientUrl + "/api/data/v8.1/";
var req = new XMLHttpRequest();
req.open("GET", oDataPath + type + "(" + MyGUID+ ")" + systemQueryOptions, async);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.onreadystatechange = function () {
if (this.readyState === 4 /* complete */) {
if (this.status === 200) {
successCallback(JSON.parse(this.response));
debugger;
}
else {
errorCallback(errorHandler(this));
}
}
};
req.send();
};
*This post is locked for comments