Hi Jim,
Here is the sample code in JavaScript:
function CheckEstimateChange(executionContext) {
var formContext = executionContext.getFormContext();
var myId = formContext.data.entity.getId(); // if its not work replace with var myId = formContext.data.entity.getId().replace("{","").replace("}","")
var FetchXML = "<fetch>" +
" <entity name='cpp_estimate' >" +
" <attribute name='statecode' />" +
" <attribute name='cpp_estimateid' />" +
" <attribute name='cpp_jobid' />" +
" <filter type='or' >" +
" <condition attribute='statuscode' operator='eq' value='923190001' />" +
" <condition attribute='statuscode' operator='eq' value='1' />" +
" </filter>" +
" <link-entity name='cpp_job' from='cpp_jobid' to='cpp_jobid' link-type='inner' >" +
" <filter type='and' >" +
" <condition attribute='cpp_jobid' operator='eq' value='"+ myId +"' />" +
" </filter>" +
" </link-entity>" +
" </entity>" +
"</fetch>";
debugger;
var encodedFetchXml = encodeURI(FetchXML);
var queryPath = "/api/data/v9.0/cpp_estimate?fetchXml=" + encodedFetchXml; // should be replaced with the entity name you are trying to query and also update version.
var requestPath = Xrm.Page.context.getClientUrl() + queryPath;
var req = new XMLHttpRequest();
req.open("GET", requestPath, true);
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
var returned = JSON.parse(this.responseText);
var results = returned.value;
if (results.length > 0) {
//---- WRITE LOGIC HERE-----------
//TODO: Implement logic for handling results as desired
}
} else {
alert(this.statusText);
}
}
};
req.send();
}
Or If you don't want to Change any code of yours please try this line :
<fetch mapping='logical' version='1.0' output-format='xml-platform' distinct='false'> instead of <fetch>
Hope this help
Thanks
Ajyendra Singh
Please Mark as verified if this answer is helpful for you.