Cloning an INCIDENT to Azure Dev Ops (Cloud)

Shane Monroe
Tera Contributor

Hi everyone.

 

I have been tasked with creating a button on INCIDENT screens that will take some of the information from the ticket and create a Work Item in ADO.

 

It seems remarkably easy in theory, but I have hit a wall that I cannot appear to climb.

 

Here is the UI action code: (instance and PAT have been redacted - but both are correct and active)

(function executeCopyToADO() {
    var requestBody = {
        "fields": {
            "System.Title": current.short_description,
            "System.Description": current.description,
            "System.State": "New",
            "Microsoft.VSTS.Common.Priority": current.urgency,
            "System.AssignedTo": "user@example.com",  // Change to dynamic assignment if needed
            "System.IterationPath": "CTSDev\\SNOW Triage",  // Change based on your ADO setup
            "System.AreaPath": "CTSDev\\SNOW Triage"
        }
    };

    var client = new sn_ws.RESTMessageV2();
client.setEndpoint('https://dev.azure.com/--redacted--/CTSDev/_apis/wit/workitems/$Bug?api-version=7.1-preview.3');

    client.setHttpMethod('POST');
    client.setRequestHeader('Content-Type', 'application/json-patch+json');
    client.setRequestHeader('Authorization', 'Basic RGxOd2JsZG--redacted-- UFBU0FaRE8xNHlC:');
    client.setRequestBody(JSON.stringify(requestBody));

    var response = client.execute();
    var responseBody = response.getBody();
    var httpStatus = response.getStatusCode();

    // Logging and UI Feedback
    gs.info("ADO API Response: " + responseBody);
    gs.info("HTTP Status Code: " + httpStatus);

    if (httpStatus == 200 || httpStatus == 201) {
        gs.addInfoMessage('Incident copied to ADO successfully!');
        current.work_notes = "Incident copied to ADO. Work item created successfully.";
        current.update();
    } else {
        gs.addErrorMessage('Failed to copy incident to ADO. Response: ' + responseBody);
        gs.error("Failed to copy incident. Response: " + responseBody);
    }
})();

 

The result when clicking the button is: 

Failed to copy incident to ADO. Response:

The response is BLANK. 

 

In the logs, we see this:

ShaneMonroe_0-1743011198430.png

A 401 error is our only useful data.  Everything else is non-descript and honestly a bit useless to us.

 

I'm hoping someone in the community has seen this cryptic issue before and can offer any sort of direction to assist us.

 

I realize that there are products to assist in this sort of implementation - but our directive was to create this in house.

 

Thank you so much in advance for any help!

2 REPLIES 2

Shree_G
Mega Sage

Hello @Shane Monroe ,

 

401 typically indicates a Authentication issue. Try overriding the authentication profiles by adding below code if you are using a basic authorization:

 

client.setBasicAuth(username,Password);

 

You can either test your configuration through "System Web Services -> Outbound -> REST Message". This also gives you a ready code that can be used in any server side script using "Preview script usage".

ShirishGhule1_0-1743077872490.png

 

ShirishGhule1_1-1743077947988.png

 

 

Shree_G
Mega Sage

Hello @Shane Monroe ,

 

If this has resolved your concern, Please mark helpful or correct to help fellow members get the resolution faster and close the thread.