I am trying to retrieve all the workorder service tasks in the field service bookable resource booking form.
I have left code with various commented out lines that I tried simplify to identify where it was failing however it never seems to enter into the function call.
When I debug it just goes straight past the entire block and I don't have any idea why.
I tried to debug by running the code in the console and noticed that when it was debugging it had pending however once out of the script would return the rows as per below images


The current code I am using is from the CRM rest builder any ideas where my error lies?
function completecheck(executionContext) {
var formContext = executionContext.getFormContext(); // get formContext
var gridContext = formContext.getControl("FsWorkOrderServiceTasksGrid"); // returns null
var wo = formContext.getAttribute('msdyn_workorder').getValue()[0].id; // returns GUID
var tasks = 0;
if (formContext.getAttribute("bookingstatus") != null && formContext.getAttribute("bookingstatus") != undefined)
{
var status = formContext.getAttribute("bookingstatus").getValue()[0].name;
if(status == "Completed")
{
// Xrm.WebApi.retrieveMultipleRecords("msdyn_workorderservicetask", "?$select=msdyn_percentcomplete,_msdyn_workorder_value&$filter=_msdyn_workorder_value eq 7ea364a4-6952-4008-bb4e-7291c34180f9 and msdyn_percentcomplete ne 100").then(
// Xrm.WebApi.retrieveMultipleRecords("msdyn_workorderservicetask", "?$select=msdyn_percentcomplete,_msdyn_workorder_value&$filter=_msdyn_workorder_value eq " woguid " and msdyn_percentcomplete ne 100").then(
Xrm.WebApi.retrieveMultipleRecords("msdyn_workorderservicetask", "?$select=msdyn_percentcomplete,_msdyn_workorder_value").then(
function success(results) {
for (var i = 0; i < results.entities.length; i ) {
tasks = results.entities.length;
console.log(results.entities[i]["_msdyn_workorder_value"]);
}
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
var faultcategory = formContext.ui.tabs.get(3).sections.get(0).controls.get(0).getAttribute("eye_faultcategory").getValue();
var incidenttype = formContext.ui.tabs.get(3).sections.get(0).controls.get(0).getAttribute("msdyn_primaryincidenttype").getValue()[0].name;
var workordertype = formContext.ui.tabs.get(3).sections.get(0).controls.get(0).getAttribute("msdyn_workordertype").getValue()[0].name;
if (status == "Completed" && (incidenttype == "Breakdown" || incidenttype == "Trapped Passenger" || incidenttype == "Repairs") && faultcategory == null) {
executionContext.getEventArgs().preventDefault(); // Stop the Save
formContext.ui.tabs.get(3).sections.get(0).controls.get(0).getAttribute("eye_faultcategory").setRequiredLevel("required")
}
else if (status == "Completed" && tasks > 0 && workordertype == "Maintenance")
{
executionContext.getEventArgs().preventDefault();
formContext.ui.setFormNotification("All WO service tasks need to be complete", "ERROR", "DurationErrorMessageId");
}
else
{
formContext.ui.tabs.get(3).sections.get(0).controls.get(0).getAttribute("eye_faultcategory").setRequiredLevel("none")
formContext.ui.clearFormNotification("DurationErrorMessageId")
}
}
}
}