Hi, recently, I met the issue that when I have a REST call, I didn't get the return value(checkApprovedShippingAddress), I assume it is related to async javascript, please advise.
if(checkApprovedShippingAddress(formContext)){ alert("1") } function checkApprovedShippingAddress(formContext){ debugger; var currentId = formContext.data.entity.getId(); var query = "ont_shippingaddresses?$select=ont_name,ont_antigenscreeningprogram&$filter=statuscode eq 122290000 and _ont_antigenscreeningprogram_value eq '" currentId "'" callAPI(query,function(data){ if(data.value.length > 0){ return true } else {return false} }) } function callAPI(query, callback) { var globalContext = Xrm.Utility.getGlobalContext(); var serverUrl = globalContext.getClientUrl(); //var ODataPath = serverUrl "/XRMServices/2011/OrganizationData.svc"; var ODataPath = serverUrl "/api/data/v9.1/"; var req = new XMLHttpRequest(); req.open("GET", ODataPath query, true); req.setRequestHeader("OData-MaxVersion", "4.0"); req.setRequestHeader("OData-Version", "4.0"); req.setRequestHeader("Accept", "application/json"); req.setRequestHeader("Content-Type", "application/json; charset=utf-8"); req.setRequestHeader("Prefer", "odata.include-annotations=\"*\""); req.onreadystatechange = function () { if (this.readyState === 4) { req.onreadystatechange = null; if (this.status === 200) { var result = JSON.parse(this.response); callback(result); } else { alert(this.statusText); } } }; req.send(); }