Quantcast
Channel: Microsoft Dynamics CRM Forum - Recent Threads
Viewing all articles
Browse latest Browse all 82002

i am trying retrieve all activities which are associated with the opportunity record by using webApi,my code goes as follows,the error it shpws is Failed to load resource: the server responded with a status of 500 (Internal Server Error),and invalid xml er

$
0
0

function activity_close() {
debugger;
var oppId = Xrm.Page.data.entity.getId().substring(1, 37);
var activityFetchXML = ['<fetch distinct="false" mapping="logical" output-format="xml - platform" version="1.0">'+
'< entity name = "activitypointer" >'+
'< attribute name = "statecode" />'+
'< attribute name = "activityid" />'+
'< filter type = "and" >'+
'< condition attribute = "regardingobjectid" operator= "eq" value = ' + oppId + ' />'+
'</ filter >' +
'</ entity >' +
'</ fetch >'].join('');
var encodedFetchXML = encodeURIComponent(activityFetchXML);
var data = {};
var serverURL = Xrm.Page.context.getClientUrl();
var req = new XMLHttpRequest();
req.open("GET", serverURL + "/api/data/v9.0/activitypointers?fetchXml=" + encodedFetchXML, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=OData.Community.Display.V1.FormattedValue");
req.onreadystatechange = function () {
if (this.readyState == 4) {
req.onreadystatechange = null;
if (this.status == 200) {
data = JSON.parse(this.responseText);
var results = new Array();
results = data.value;
for (var i = 0; i <= results.length; i++) {
var statecode = results[i]["statecode"];
var primaryActivityId = results[i]["activityid"];
if (statecode != 1) {
alert("opportunity cannot be closed since activities are not completed or canceled");
}

}

} else {
var error = JSON.parse(this.responseText).error;
(error.message);
}
}
};
req.send();
}

can anybody please suggest what could be wrong in the above code,i am trying retrieve all activities which are associated with the opportunity record by using webApi fetchXml querying method.


Viewing all articles
Browse latest Browse all 82002

Latest Images

Trending Articles



Latest Images