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',
'Accept':'application/json'
},
type: 'POST',
url: "https://<server>:9443/ccm/oslc/contexts/<projectAreaItemId>/drafts/workitems",
data:"{"dc:title":"YAY","dc:type":{"rdf:resource":"https://<server>:9443/ccm/oslc/types/<projectAreaItemId>/com.ibm.team.workitem.workItemType.task"}}"

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 Jazz.net 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?

Thanks,
Dave

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/com.ibm.team.workitem.WorkItem/_HL4hMIZmEeqfEekxQfni2w?draftId=_HL69cIZmEeqfEekxQfni2w

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:
https://<server>/ccm/web/projects/<projectName>?draftId=_HL69cIZmEeqfEekxQfni2w#action=com.ibm.team.workitem.newWorkItem&draftId=_HL69cIZmEeqfEekxQfni2w&type=com.ibm.team.workitem.workItemType.task

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";

$.ajax({
    async:true, xhrFields: {withCredentials: true}, url: URL,
    type: 'POST',
    data: str,
    headers:{
    'Content-Type' : 'application/json',
    'Accept':'application/json'
    },
    success: function(response, status, xhr){
        let location = xhr.getResponseHeader("location");
        let draftId = location.substr(location.indexOf('draftId='));
        let url = projectURL + "?" + draftId + "#action=com.ibm.team.workitem.newWorkItem&" + draftId + "&type=" + WITypeId;
        window.open(url, "_blank");
    },
    error: function(error){
        alert(error.responseJSON['oslc_cm:message']||error);
    }
});

Your answer


Register or to post your answer.