It's all about the answers!

Ask a question

OSLC API - Create Draft Work Item Ignoring Work Item Type

Dave Evans (1242032) | asked Apr 24, 2:05 p.m.

I believe I am doing this right, but need a double check. I think I should be able to create a work item using an AJAX request from an authenticated session, with these settings:

headers: {
'Content-Type' : 'application/json',
type: 'POST',
url: "https://<server>:9443/ccm/oslc/contexts/<projectAreaItemId>/drafts/workitems",

I can see in the response that the work item draft has the correct work item type (task), but when I open the editor using the location URL provided in the response header, the work item editor contains the correct 'Summary' (title) as expected, but the work item's type is the project's default work item type instead of the one specified.

I've spent time researching solutions on and it looks like several people are having the same problem. Can I get correct instructions from the developers, or confirmation if it is a defect in the tool?


One answer

permanent link
Dave Evans (1242032) | answered Apr 24, 4:17 p.m.

I got it working.

The 'Location' property needs to be taken and modified.

For example, my response header has:
Location: https://<server>/ccm/resource/itemOid/

But if you go there, it opens the editor with the default work item type (virtually useless if it can't even get the type right).

However, if you take information like the draftID from the location, and build a URL like this, it works:

Note: I am using 6.0.6. And I am using an AJAX request WITHOUT the OSLC version header. Here is my full AJAX request for the work item post:
var simpleWI = new Object();
simpleWI['dc:type'] = new Object();
simpleWI['dc:type'][rdf:resource'] = (Work Item Type URL);
simpleWI['dc:title'] = "Any title you desire";

var str = JSON.stringify(simpleWI);
var URL = RTCURL() + "oslc/contexts/" + ProjectItemId + "/drafts/workitems";

    async:true, xhrFields: {withCredentials: true}, url: URL,
    type: 'POST',
    data: str,
    'Content-Type' : 'application/json',
    success: function(response, status, xhr){
        let location = xhr.getResponseHeader("location");
        let draftId = location.substr(location.indexOf('draftId='));
        let url = projectURL + "?" + draftId + "" + draftId + "&type=" + WITypeId;, "_blank");
    error: function(error){

Your answer

Register or to post your answer.