first question here. I am developing a program that needs to query my azure devops organization and return a list of work item references filtered by System.Tag and System.TeamProject.
To do this, I decided to use azure-devops-node-api's queryByWiql() function in the following way:
//create a new WIQL object of data we want
const query: string = "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = [" + this.globals.API_PROJECT + "] AND [System.Tags] Contains [" + tag + "]";
console.log(query);
//create a new TeamContext object so the query knows where to look
const projectId = this.globals.API_PROJECT;
//ping ADO with this query
const result: WorkItemTrackingInterfaces.WorkItemQueryResult = await WorkItemApiObject.queryByWiql({query: query}, {project: projectId}); //WHY DOESNT THIS WORKKKKKK
where 'this.globals.API_PROJECT' is a string referencing the project name and 'tag' is a string of the name of the tag I want to query work-items by.
The thing is, when I call queryByWiql() with parameters 'this.globals.API_PROJECT' = projectName and 'tag' = tagName (just random parameters: I get the same error message no matter what), I get the following error:
Failed to load resource: the server responded with a status of 400 () from dev.azure.com/{organization}/{project}/_apis/wit/wiql:1
ERROR Error: Uncaught (in promise): Error: TF51005: The query references a field that does not exist. The error is caused by «projectName».
at RestClient.<anonymous> (RestClient.js:202)
at Generator.next (<anonymous>)
at fulfilled (RestClient.js:6)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:27148)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:27136)
at resolvePromise (zone-evergreen.js:798)
at zone-evergreen.js:705
at rejected (tslib.es6.js:72)
at ZoneDelegate.invoke (zone-evergreen.js:364)
at Object.onInvoke (core.js:27148)
at ZoneDelegate.invoke (zone-evergreen.js:363)
at Zone.run (zone-evergreen.js:123)
at zone-evergreen.js:857
at ZoneDelegate.invokeTask (zone-evergreen.js:399)
at Object.onInvokeTask (core.js:27136)
The problem is, I know for a fact that projectName and tagName exist in the project and organization I am querying. I also know that I am using the correct references to these fields "System.Tag" and "System.TeamProject" since I went and checked my project for these specifically.
All I want to do is get a type WorkItemTrackingInterfaces.WorkItemQueryResult from this call. Please help! Thank you for your time.
EDIT1: Added Resource Load Fail error message since that also happens.
UPDATE: I fixed it. I feel so silly for not doing this. Turns out I misunderstood what brackets [] are supposed to be in WIQL-- They are only supposed to represent fields. To indicate strings with spaces and special characters, surround the string with '', like the following:
const query: string = "SELECT [System.Id] FROM WorkItems WHERE [System.TeamProject] = '" + this.globals.API_PROJECT + "' AND [System.Tags] Contains '" + tag + "'";
...yeah, turns out it was a syntax error all along. I feel so silly LOL. I spent so much time on this haha