Synia Synia -4 years ago 145
Javascript Question

VSTS - Widget only works for some people anod not others. What might be the issue?


I've built a widget that works for some people in the company, but not other people and I was wondering if anyone might help me.

For the people that it works for, it doesn't matter what computer or browser they are on, it works. While for thosethat it does not work for, it just doesn't work no matter what computer or browser they use.

The Widget is very simple. It builds a query using the query API before plotting the result on a graph.

The main problem seems to be that the query is returning zero result for some people, for some unknown reason.

It doesn't seem to have anything to do with licenses or security permission as some people on stackholder licenses can see the widget, while others on basic license with project admin permission cannot.

Any suggestions would be much appreciated.


First, I have a method that builds the query depending on the type of query I want.

var queryString = buildWiql(queryType, dateString, iterationPath);

The implementation of

var buildWiql = function (queryType, dateString, iterationPath) {

var queryString;

if (queryType=== "someType") {
queryString = {
"query": "Select [Microsoft.VSTS.Scheduling.RemainingWork] From WorkItems Where [System.WorkItemType] = 'Task' AND [System.State] <> 'Done' AND [System.State] <> 'Closed' AND [System.IterationPath] = '" + iterationPath + "' order by [System.CreatedDate] desc ASOF " + dateString
else if (queryType === "someOtherType") {
else {

return queryString;

Then inside the main function:

return TFS_Wit_WebApi.getClient().queryByWiql(queryString)
.then(function (query) {

When the console logs the query result. For those whom it doesn't work for, the query returns an array with 0 elements.

For accounts that the widget doesn't work for. Opening the console in the browser gives this error:

Failed to load resource: the server responded with a status of 400 (Bad Request)
Error: Expecting date-time. The error is caused by <<'20/8/2016'>>.(....)

Answer Source

The problem with the widget was that apparently, everyone can have a different date-time format preference set in their profile. eg. '25/08/2016' vs '25 Aug 2016'.

However, my widget assumed that the format was always 'dd/MM/yyyy', which is the format of the dateString it passes into the 'ASOF' part of the query.

For users who's got a different date-time format setting. The result would be zero, because VSTS wouldn't understand what '25/08/16' is

The solution is to convert the string into this format: 2016-08-20T20:49:34.193Z

And now, regardless of the user's date-time format setting, the query will return correct results. The code I used to do the conversion is:

var dateToString = function (dateIn) {

    var date = new Date(dateIn.getTime() + 86400000);
    var day = date.getDate();
    var month = date.getMonth() + 1;
    var year = date.getFullYear();

    //Format date as '2016-08-20T20:49:34.193Z'"
    var dateString = year + '-' + month + '-' + day + 'T00:00:00.000Z';

    return dateString;

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download