Just starting out with async programming and I've noticed a common issue in similar threads - the problem of not returning anything. However, in my case, I am facing a different error message 'Cannot read property 'then' of undefined'.
function getWorkItems(iterationPath, projectId) {
var queryClient = VSS_Service.getCollectionClient(TFS_Wit_QueryAPI.WorkItemTrackingHttpClient);
var query = { query: "SELECT [System.Id] FROM WorkItem WHERE [System.IterationPath] = '" + iterationPath + "'" };
var resultOfQuery;
queryClient.queryByWiql(query, projectId).then(
function (resultOfQuery) {
return new Promise((resolve, reject) => {
resolve(resultOfQuery);
console.log("Debug: " + JSON.stringify(resultOfQuery));
})
VSS.notifyLoadSucceeded();
});
}
Although the debug message is printed successfully and data is fetched from the server, an error occurs when calling it from another location.
let bar;
getWorkItems(counter.path, projectId).then ( res => {
bar = res;
console.log("Debug: should be output of query " + JSON.stringify(bar));
})
The error message 'Cannot read property 'then' of undefined' pops up in this scenario.