Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

OSLC API - Create Draft Work Item Ignoring Work Item Type

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

0 votes



One answer

Permanent link

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);
    }
});

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details
× 10,948
× 7,503
× 1,333
× 516
× 369
× 60

Question asked: Apr 24 '20, 2:05 p.m.

Question was seen: 2,831 times

Last updated: Apr 24 '20, 4:17 p.m.

Related questions
Confirmation Cancel Confirm