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.4k6181201) | 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).


try {
IProgressMonitor sPm = new SysoutProgressMonitor();
// get operations handle to repository

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

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

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

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.


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

Your answer

Register or to post your answer.