Check the blue colored code i want to concatenate the array in new flags and return it to the field in CRM which is commonflag. But it alerts [Object Object]... and its repeated pairs. So, please correct this one.
function Testing() {
var GUIDvalue = Xrm.Page.data.entity.getId();
alert(GUIDvalue);
var fetchXml = "<fetch mapping='logical' distinct='false'>"
+ "<entity name='account'>"
+ "<attribute name='new_choosedflag' alias='flagstring'/>"
+ "<link-entity name='account' from='accountid' to='accountid' link-type='inner' alias='ab'>"
+ "<filter type='and'>"
+ "<condition attribute='accountid' operator='under' value='" + GUIDvalue + "' />"
+ "</filter>"
+ "</link-entity>"
+ "</entity>"
+ "</fetch>";
alert(fetchXml);
var fetch = encodeURI(fetchXml);
var entityname = "accounts";
var serverURL = Xrm.Page.context.getClientUrl();
var Query = entityname + "?fetchXml=" + fetch;
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v9.0/" + Query, false); //Removed api from url domain
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.send();
if (req.readyState == 4) { /* complete */
req.onreadystatechange = null;
if (200 == req.status) {
debugger; // Try to debug in this point to get the count if any error you get
var results = JSON.parse(req.response);
var flags="";
for (var i = 0; i < results.value.length; i++)
{
alert("inside for");
flags += results.value[i]+", ";
alert(flags);
}
var newResult = flags.slice(0, -2);
Xrm.Page.getAttribute("new_commonflag").setValue(newResult);
}
else {
console.log(req.statusText);
}
}
}/*
var totalcount = results.value[0].recordcount;
Xrm.Page.getAttribute("new_orgcasecount").setValue(totalcount);*/
*This post is locked for comments