How to add Links to a Workitem in RTC 5.x (JS/Dojo)
Hy there fellas,
Does someone know how to add a "parentLink" to an existing Workitem. The Idea is to clone a WI and then add the parent link to the cloned WI. Maybe I can relate the WI on creation with the Link? I use this class to get the Item: com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory var params = { includeHistory: false, newWorkItem: true, projectAreaItemId: pid, typeId: "com.ibm.team.apt.workItemType.story" } var newProxy = WorkItemProxyFactory.getWorkItemProxy(params); //Create new Item: newProxy.initialize(projectArea, type, newWorkitem, includeHistory) //Maybe it's possible to add links here? //Before I add some attributes like name, description etc //My Idea here was, to extract the Links, and add it in the same way to the new Item. workItemToSave.storedObject.linkTypes = parentLink; //itemToSave is "newProxy" //Store, save it on the DB newProxy.storeWorkItem(); |
Accepted answer
Hy Ralph,
I don't really like blogging. But I'll describe it here. First you should read this Post about how the whole Workitem-System works. https://jazz.net/wiki/bin/view/Main/WorkItemWebItemProxyDesign Long story short: With store and fetch you interact direct with the REST-Client (Store on DB) Store = Save it on DB Fetch = Get it from DB Everything in this "workItemproxy" is kinda like a runtime copy of the actual WI. Now I gonna try to clarify how to interact with those Workitems. First, get the workItemProxy class. dojo.require("com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory"); I instantiate it for easier use: var WorkItemProxyFactory = com.ibm.team.workitem.web.cache.internal.WorkItemProxyFactory; Now we gonna create a new WIProxy: var params = {createIfNeeded: true}; var newProxy = WorkItemProxyFactory.getWorkItemProxy(params); //If you want an WIProxy of an existing WI: var params = { id: "itemId of the wished WI", createIfNeeded: true, doNotCache: true, doNotGetFromCache:true}; var workingCopyProxy = WorkItemProxyFactory.getWorkItemProxy(params); //Initialize the WI //After the initialization, you'll see an unsaved WI in the MenuBar "Work Items". var params = {projectAreaItemId: "The ItemId of your project", type: "com.ibm.team.apt.workItemType.story", //Story, epic, whatever you need newWorkItem: true, includeHistory: false}; newProxy.initialize(params); //Get the Links from the workingCopy var linkTypeArray = workingCopyProxy.object.linkTypes //Here are all Links to this actual WI stored. //Otherwise you could use: var linkTypeArray = workingCopyProxy.getLinkTypesToWorkItem(workingCopyProxy); //If you search specific LinkTypes, use the endpointId //I.E. linkTypeArray[x].endpointId == 'parent' //To get the parentLink //Now HOW TO ADD THE WISHED LINKS var param = { addLinkType: linkTypeArray, //It has to be an Array addLinkedProjectAreaItemId: null, //I don't know what this shold do. addLinkedItemId: newProxy.object.itemId, // It's the ItemId of itself addLinkIsSource: linkTypeArray[0].isSource, //Mostly this is "false" } newProxy.addLinkTarget(param); //At this point ONLY your runtime copy is actualized! You have to store now your WI to save it on the DB newProxy.storeWorkItem({ self: this, operationMsg: "Saving", applyDelta: true, onSuccess: function(param) { //Do what you need } }); Et Voilà the Item is created and saved with the wished links. Ralph Schoon selected this answer as the correct answer
Comments
Ralph Schoon
commented Oct 31 '14, 10:05 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
One last comment Jonas.
Jonas Studer
commented Oct 31 '14, 10:49 a.m.
Ok, sory for that!
Hello,
Hello Vinitha,
HI,
did you resolve your problem? I'm trying to button for create children workitem and on StoreWorkitem I'm getting error:
Uncaught TypeError: Cannot read property 'id' of undefined
at Object._getSaveAppArgs_$77 [as _getSaveAppArgs] (com.ibm.team.workitem.web.cache.internal.WorkItemProxyClient.js?debug=true&etag=aT34qru&locale=en-us&_proxyURL=%2Fjazz:2020)
at Object.storeWorkItem_$64 [as storeWorkItem] (com.ibm.team.workitem.web.cache.internal.WorkItemProxyClient.js?debug=true&etag=aT34qru&locale=en-us&_proxyURL=%2Fjazz:1515)
at Object.run_$1 [as run] (corp.bury.webui.findingButton.ui.createFindingAction.js?debug=true&locale=en-us&_proxyURL=%2Fjazz:65)
at Object._doRun_$2 [as _doRun] (com.ibm.team.workitem.web.ui2.internal.action.AbstractAction.js?debug=true&etag=aT34qru&locale=en-us&_proxyURL=%2Fjazz:59)
at Object.method_$16 [as onClick] (dojo._base.lang.js?debug=true&etag=aL4Yoz2&locale=en-us&_proxyURL=%2Fjazz:375)
at Object._onClick_$3 [as _onClick] (jazz.ui.toolbar.Button.js?debug=true&etag=aT18Sli&locale=en-us&_proxyURL=%2Fjazz:126)
at Object.onClick_$9 (net.jazz.ajax.ui.ScenarioRegistry.js?debug=true&etag=aT174Ja&locale=en-us&_proxyURL=%2Fjazz:204)
at Object.<anonymous> (dojo._base.lang.js?debug=true&etag=aL4Yoz2&locale=en-us&_proxyURL=%2Fjazz:327)
at HTMLAnchorElement.method_$16 (dojo._base.lang.js?debug=true&etag=aL4Yoz2&locale=en-us&_proxyURL=%2Fjazz:375)
My code is here:
|
One other answer
I don't think you can create or follow links in the javascript api.
Comments
Jonas Studer
commented Oct 29 '14, 10:21 a.m.
Hy Sam,
sam detweiler
commented Oct 29 '14, 10:30 a.m.
No idea.. never got links to work (list, create, delete, or follow) in javascript.
Ralph Schoon
commented Oct 29 '14, 10:37 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
There is a distinction between JavaScript in workitemCustomization, where you can't even access links and creating your own web pages and contributions to them, where you potentially could (as the tool has such capabilities as well)
sam detweiler
commented Oct 29 '14, 10:40 a.m.
thanks for that clarification.. I've never done the latter.. (UI is not my thing!)
So I got in a bit deeper.
Ralph Schoon
commented Oct 29 '14, 12:29 p.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
This is beyond my expertise as well. Sorry.
It would be great is this could be shared somewhere. If it was my work and I knew how it works, I would blog about it. If you really want to it would be cool if you blogged about it e.g. on DeveloperWorks and link that back here.
showing 5 of 7
show 2 more comments
|
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.