It's all about the answers!

Ask a question

Calling Work Item Template Invocation from Code


Gary Mullen-Schultz (28725536) | asked Mar 29 '12, 5:12 p.m.
Does anyone have a code sample that shows how I could programatically create work items from a work item template? We would like to be able to set more fields than just "Filed Against" and "Planned For."

Thanks, Gary

3 answers



permanent link
sam detweiler (12.5k6195201) | answered Mar 30 '12, 5:23 p.m.
sorry, no.. haven't played with templates at all.

permanent link
Gary Mullen-Schultz (28725536) | answered Mar 30 '12, 11:19 a.m.
Thanks for the reply.

I don't want to programmatically create just a work item, but several work items via an existing work item template. Right now, those are the only two "variable" fields that can be set when creating from a work item template.

Any idea on how to do this? Thanks.

Gary

permanent link
sam detweiler (12.5k6195201) | answered Mar 29 '12, 10:23 p.m.
and why do you think you can only set those fields?

here is one of my java client code sections that creates a new workitem. this is called from a web service, passing the parameters from another system. You build a map of all the fields and values, and 'save that' with the new workitem.
(the synchrule stuff is due to the internal processing my handler provides).

 		if(!TeamPlatform.isStarted())

TeamPlatform.startup();
try {
IProgressMonitor sPm = new SysoutProgressMonitor();
if(login(sPm)!=null)
{
// get operations handle to repository



IExternalProxy proxy = getExternalProxy(getRepository(),createItem.getProblem(),true, sPm);
IExternalState externalState = InteropFactory.INSTANCE
.createExternalState();
ISyncRule sr = getInteropMgr().findSyncRule(
StringConstants.sfdcworkitem, sPm);
proxy = (IExternalProxy) proxy.getWorkingCopy();
proxy.setSyncRule(sr);

Map<String> states = new HashMap<String>();
System.out.println("processing workitem create\n");
states.put(StringConstants.CreateOnlyType, "defect");
states.put(StringConstants.CreateOnlyfiledAgainst, createItem.getProduct());
states.put(StringConstants.CreateOnlyProblemNumber, createItem.getProblem());
states.put(StringConstants.CreateOnlySummary, createItem.getSummary());
states.put(StringConstants.CreateOnlyCreatedBy, StringConstants.UserPrefix +":"+ createItem.getAuthor());
states.put(StringConstants.CreateOnlyDescription, createItem.getDescription());
java.sql.Timestamp js = new java.sql.Timestamp(java.lang.System.currentTimeMillis());
states.put(StringConstants.CreateOnlyCreationDate, js);
states.put(StringConstants.CommonLastSynch, js);

states.put(StringConstants.CommonStatus, "Initial");
states.put(StringConstants.CommonPriority, createItem.getPriority());
states.put(StringConstants.CommonSeverity, createItem.getSeverity());
states.put(StringConstants.CommonCases,CasestoList(createItem.getCases()));
states.put(StringConstants.CommonComments,CommentstoList(createItem.getComments(),true));
states.put(StringConstants.CommonAttachments,AttachmentstoList(createItem.getAttachments()));
states.put(StringConstants.CommonImpact,createItem.getImpact());
states.put(StringConstants.CommonReproduction,createItem.getHowtoreproduce());
states.put(StringConstants.CommonCircumvention,createItem.getCircumvention());

// save the updated states
externalState.setState(states);
//interop.setSynchronizationEnabled(sr, true, sPm);
// persistently
getInteropMgr().saveProxyWithState(proxy, externalState, sPm);

Your answer


Register or 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.