Problem
Recently got one issue reported from old code where FetchXML request is executed with XrmServiceToolkit. It was throwing “TypeError: Cannot read property ‘value’ of null”.
Solution
We are already in process of upgrading all the old code to new Xrm.WebApi code but this was kind of showstopper as custom html web resource was not loading because of this issue. To solve this issue we removed XrmServiceToolkit and replaced it with new Xrm.WebApi request like below and it started working again.
async function ExecuteFetchXML(entityname,fetchxmlreq) { fetchxmlreq = "?fetchxmlreq=" + encodeURIComponent(fetchxmlreq); //using this request on the html webresource so need to use window.parent before Xrm.WebApi await window.parent.Xrm.WebApi.retrieveMultipleRecords(entityname, fetchxmlreq).then( function success(response) { return response.entities; } }, function (error) { return null; } ); //We can call above method using like following var fetchxmlreq="FetchXRML Query"; var FetchXMLResponse = await ExecuteFetchXML("account",fetchxmlreq);
You can create fetchxmlreq using XrmToolBox fetch xml editor or can use AdvancedFind to design and download it.
Hope it will help someone!
Keep learning, Keep sharing !!
Pingback: TypeError: Cannot read property ‘value’ of null - Microsoft Dynamics CRM Community