尝试使用WIQL获取工作项时发生VSTS/TFS错误 [英] VSTS / TFS Error Occurred While Trying to get Work Items With WIQL

查看:169
本文介绍了尝试使用WIQL获取工作项时发生VSTS/TFS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下方法从VSTS扩展名获取具有特定标题的工作项ID.我正在使用REST API,Typescript和WIQL.

I am using below method to obtain workitem Ids with specific title from my VSTS extension. I am using REST API , Typescript and WIQL .

public getWorkItemsbyQueryFilter(): string[] {               

            try {               

                let query =  "Select [System.Id] From WorkItems Where [System.WorkItemType] = '" + this.workItemType + "' AND [System.Title] contains 'ABC'";
                var ids : string[];           
                var self = this;
                var colURL =  this.collectionURL +this.teamProject +"/_apis/wit/wiql?api-version=1.0"

                var options = {            
                    url: colURL,
                    username: this.username,
                    password: this.password,
                    domain: this.domain,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }, 
                    body :{
                        'query': query
                    }         
                };

                httpntlm.post(options, function(err,res) {

                    if(err) {
                        console.log("Error : +"+ err)
                        deferred.reject(err);
                    }
                    var obj = JSON.parse(res.body);

                    for (var index = 0; index < obj.workItems.length; index++) {
                       ids.push(obj.workItems[index].id);                   
                    }             

                    return ids;
                });       

            } catch (error) {
                console.log("Failed to Get Work Item Ids :"+ error);               
            }
        }

执行此方法时出现以下错误.根据我的网络研究,我找不到解决该问题的方法

I got below error when I execute this method . As per my web research I couldn't find much to resolve this issue

未处理:必须以数字,缓冲区,数组或字符串开头

Unhandled: must start with number, buffer, array or string

接下来,我尝试在邮递员(chrome扩展名)中尝试此请求.我在同一个新错误. Json似乎有问题,但我无法弄清楚到底是什么.请足够友善以显示光线.

Next I have try this request in postman (chrome extension). I am getting new error in same. It seems like something wrong with Json ,but I couldn't figure out what exactly it is. Please be kind enough to show some light.

{"count":1,"value":{"Message":"Error converting value \"query\" to type 'Microsoft.TeamFoundation.WorkItemTracking.Web.Models.Wiql'. Path '', line 1, position 7.\r\n"}}

推荐答案

非常感谢帮我.我能够弄清楚并解决此问题.我必须使用"json"而不是"body"来解决此问题(请检查下面的代码..但是我在邮递员中仍然遇到相同的错误.仍在尝试弄清楚其给出错误的原因).

Thanks a lot for help me out. I was able to figure it out and fix this issue. I have to use "json" instead of "body" to fix this issue (Please check below code ..However I still get same error in postman . Still trying to figure-out why its giving error).

 var options = {            
                    url: colURL,
                    username: this.username,
                    password: this.password,
                    domain: this.domain,
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    }, 
                    json :{
                        'query': query
                    }         
                };

这篇关于尝试使用WIQL获取工作项时发生VSTS/TFS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆