Mentioning a user in the System.History

青春壹個敷衍的年華 提交于 2021-02-10 14:26:47

问题


I'm trying to add a new comment to a work item which mentions a user, but using the traditional "@adamh" as you would do on the website does not seem to work via the API.

The data updates fine, however the "@adamh" is just plain text, I need to be able to somehow chuck an identity into here. Can anyone point me in the right direction?

Thanks!

A snippet is here

const vsts = require('vso-node-api');
const item = require('vso-node-api/WorkItemTrackingApi')
const ti = require('vso-node-api/interfaces/WorkItemTrackingInterfaces');
// your collection url
const collectionUrl = "https://myArea.visualstudio.com/defaultcollection";
// ideally from config
const token = "helloWorld";


async function run() {
    let authHandler = vsts.getPersonalAccessTokenHandler(token);
    let connection = new vsts.WebApi(collectionUrl, authHandler);
    let itemTracking = await connection.getWorkItemTrackingApi();
    //Add all task data to new array
    let taskData = await itemTracking.getWorkItems([15795,15796])

    let newData = taskData[0]

    let wijson = [
        {
            "op": "add",
            "path": "/fields/System.History",
            "value": "@adamh"
        }
    ];

    const updateItem = itemTracking.updateWorkItem(null, wijson, 15795).catch(err => {
        console.log(err)
    }).then(() => console.log("updated"))

    return newData
}

const express = require('express')
const app = express()

app.get('/', async (req, res) => {
    let data = await run()
    res.send(data)
})

app.listen(3000, () => console.log('Example app listening on port 3000!'))

回答1:


You can use the @ to notify another team member about the discussion. Simply type @ and their name.

It's using the @mention control , the person you @mention will receive an email alert with your comment and a link to the work item, commit, changeset, or shelveset.

There is not any public API shows how this work in VSTS, you could try to use F12 in google browser to track the process. Another workaround is directly using API to send a notification to the user you want to mention at.




回答2:


You can use the format shown here as part of the text value for your new comment:

<a href="#" data-vss-mention="version:2.0,userid"> ... </a>

This will create a mention link to that user. The link text can be the person's name or any other text you choose to put there. An email alert will be sent to the mentioned user if your system is configured to do so (same as in the UI).

To get your users' userid strings, you can follow the method shown here.



来源:https://stackoverflow.com/questions/51378893/mentioning-a-user-in-the-system-history

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!