-1

I have an extension on devops azure, and I 'm newbie in Javascript by the way. I wrote an function to get the name of task after fetch its id from server:

dataService.getDocument("registryKey").then((doc) => {
    let authenToken =  doc.value[doc.count - 1];
    fetch('https://52.221.253.35/api/timelog'+query, {
       method: 'GET',
       headers:{
          'Authentication': authenToken
       }
   }).then((resp) => resp.json()).then(function (data) {
         let index = 1;
         let body = "";
         // foreach the data and i call VSS Http to get work item 's detail
         data.forEach(async function f(item) {
             let result = await witClient.getWorkItems(item.TaskId, ["System.Id", "System.Title"]);
                        body+="<p>"+result['System.Title']+"</p>"
                    $("#table-body").html(body);
                });

but when it runs, it throws an error: Uncaught (in promise) TypeError: n.join is not a function What is wrong here? Thank you for your comment.

avocadoLambda
  • 1,332
  • 7
  • 16
  • 33
Erics Nguyen
  • 370
  • 4
  • 16
  • 1
    Well whatever the problem is, it is not part of the code you have supplied. – see sharper Jun 30 '20 at 05:03
  • i inspect chrome, and the console log throw the error indicate the error come from that code – Erics Nguyen Jun 30 '20 at 06:23
  • Yes, but not in the code you provided, which I can tell because it does not contain `n.join`. So possibly it is in library code being called by your code. The stack trace should tell you what line of your code was responsible. – see sharper Jun 30 '20 at 06:26
  • yes, thank you, i see, so it broken on this line: `witClient.getWorkItems(item.TaskId, ["System.Id", "System.Title"]);` – Erics Nguyen Jun 30 '20 at 06:31

1 Answers1

1

Try this:

let result = await witClient.getWorkItems([item.TaskId], ["System.Id", "System.Title"]);
                    body+="<p>"+result['System.Title']+"</p>"
                $("#table-body").html(body);
            });

Note the square brackets around the first parameter.

see sharper
  • 11,505
  • 8
  • 46
  • 65
  • i try your solution, but when i debug, it jumped to `$("#table-body").html(body);` before jump on `body+="

    "+result['System.Title']+"

    "`
    – Erics Nguyen Jun 30 '20 at 06:50
  • yes, but can you explain to me why it jump to `$("#table-body").html(body);` before `body+="

    "+result['System.Title']+"

    "`
    – Erics Nguyen Jun 30 '20 at 07:00
  • I can't. Because you haven't supplied the code context. But that is a separate question - please post a new one if you can't work out what's going on. – see sharper Jun 30 '20 at 07:03