0

I am trying to create a query using the following- https://www.visualstudio.com/en-us/docs/integrate/extensions/reference/client/api/tfs/workitemtracking/restclient/workitemtrackinghttpclient2_2#method_createQuery

I am developing a vsts extension using above. This is the code-

import { QueryHierarchyItem  } from "TFS/WorkItemTracking/Contracts";
var postedQuery = [

    {
        "children": [],
        "clauses": {
            "field": {
                "referenceName": "System.WorkItemType",
                "name": "Work Item Type",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/System.WorkItemType"
            },
            "operator": {
                "referenceName": "SupportedOperations.Equals",
                "name": "="
            },
            "value": "Bug"
        },

        "columns": [
            {
                "referenceName": "System.Id",
                "name": "ID",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/System.Id"
            },
            {
                "referenceName": "System.Title",
                "name": "Title",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/System.Title"
            },
            {
                "referenceName": "System.State",
                "name": "State",
                "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/System.State"
            }
        ],
        "createdBy": {
            "id": "d291b0c4-a05c-4ea6-8df1-4b41d5f39eff",
            "displayName": "Jamal Hartnett <fabrikamfiber4@hotmail.com>"
        },
        "createdDate": "2016-06 - 01T16: 58:56.64Z",
        "filterOptions": "WorkItems",
        "hasChildren": false,
        "id": "df60fdf6-3b5f-4928-aae8-29ee63df6e31",
        "isDeleted": false,
        "isFolder": false,
        "isInvalidSyntax": true,
        "isPublic": false,
        "lastModifiedBy": {
            "id": "d291b0c4-a05c-4ea6-8df1-4b41d5f39eff",
            "displayName": "Jamal Hartnett <fabrikamfiber4@hotmail.com>"
        },
        "lastModifiedDate": "2016-06 - 01T16: 58:56.64Z",
        "name": "All Bugs",
        "path": "Shared Queries",
        "queryType": "flat",
        "sortColumns": [
            {
                "field": {
                    "referenceName": "Microsoft.VSTS.Common.Priority",
                    "name": "Priority",
                    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/Microsoft.VSTS.Common.Priority"
                },
                "descending": false
            },
            {
                "field": {
                    "referenceName": "System.CreatedDate",
                    "name": "Created Date",
                    "url": "https://fabrikam-fiber-inc.visualstudio.com/DefaultCollection/_apis/wit/fields/System.CreatedDate"
                },
                "descending": true
            }
        ],

        "wiql": "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc",


    }

]



 let queryPath = "Shared Queries";
    let Query: QueryHierarchyItem = postedQuery;

   client.createQuery(Query, "Team_P1", queryPath).then((wi) => {


    },
        (query) => {


        });

enter image description here

Thomas Smyth - Treliant
  • 4,993
  • 6
  • 25
  • 36
Anusha B
  • 95
  • 1
  • 1
  • 8

2 Answers2

0

By default the tsc compiler will truncate the error message to 100 characters.

You can change it by setting "noErrorTruncation": true in the compilerOptions property of your tsconfig.json file.

See Typescript Compiler Options for more details

The error message is now (after beautifying)

'Type ' { "children": any[]; "clauses": { "field": { "referenceName": string; "name": string; "url": string; }; "operator": { "referenceName": string; "name": string; }; "value": string; }; "columns": { "referenceName": string; "name": string; "url": string; }[]; "createdBy": { "id": string; "displayName": string; }; "createdDate": string; "filterOptions": string; "hasChildren": boolean; "id": string; "isDeleted": boolean; "isFolder": boolean; "isInvalidSyntax": boolean; "isPublic": boolean; "lastModifiedBy": { "id": string; "displayName": string; }; "lastModifiedDate": string; "name": string; "path": string; "queryType": string; "sortColumns": { "field": { "referenceName": string; "name": string; "url": string; }; "descending": boolean; }[]; "wiql": string; }[] ' is not assignable to type 'QueryHierarchyItem'. Property 'children' is missing in type [type repeated]. '

you declared postedQuery as an array [] whereas QueryHierarchyItem that's why property children is missing.

If you remove the array you will have new error messages with missing properties and so on.

By the way, based on this link it doesn't look you need to create the whole object, you can create an empty object an assigning the required parameters.

let queryPath = "Shared Queries";
let query: <QueryHierarchyItem>{};
query.Name = 'Query Name'; 
query.wiql = '...'

client.createQuery(query, "Team_P1", queryPath)
      .then(wi => {
          console.log(wi);             
      }, q => {
          console.log(q);
      });
Cyril Durand
  • 15,834
  • 5
  • 54
  • 62
  • If the solution is working, please mark the answer as accepter, it will help others to find this answer. See https://stackoverflow.com/help/someone-answers for more information :) – Cyril Durand Feb 23 '18 at 17:01
0

First, you can refer to Cyril’s answer.

Secondly, you can refer to this code instead:

let Query:any={
            name:"Api Query",
            wiql: "Select [System.Id], [System.Title], [System.State] From WorkItems Where [System.WorkItemType] = 'Bug' order by [Microsoft.VSTS.Common.Priority] asc, [System.CreatedDate] desc"
        };
let queryPath = "Shared Queries";


   client.createQuery(Query, "Team_P1", queryPath).then((wi) => {


    },
        (query) => {


        });
starian chen-MSFT
  • 33,174
  • 2
  • 29
  • 53