It's all about the answers!

Ask a question

Error on saving workitem - Team Concert Extension - On State Change Participant

Juan Martín Alberti (201417) | asked Apr 30 '14, 11:04 a.m.
I have built a workflow where a role is not allowed to modify a contributor type field.

And I have built an extension that runs on work item state change participant.

On that extension I modify the field that the role can't modify. I want that this field could be modified by the extension but no by the user with the denied role.

The code that I execute is this:

IWorkItemCommon wiCommon = getService(IWorkItemCommon.class);
IAttribute attAbogado = wiCommon.findAttribute(projectArea, "abogado", monitor);
IAttribute attOwner = wiCommon.findAttribute(projectArea, IWorkItem.OWNER_PROPERTY, monitor);
IWorkItem workingCopy = (IWorkItem) fWorkItemServer.getAuditableCommon().resolveAuditable(newState, IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();
workingCopy.setValue(attAbogado, oAbogadoPorAsignar);
workingCopy.setValue(attOwner, oAbogadoPorAsignar);
//fWorkItemServer.saveWorkItem2(workingCopy, null, null);
HashSet additionalSaveParameters = new HashSet();
//IAdditionalSaveParameters additionalSaveParameters = new IAdditionalSaveParameters();
fWorkItemServer.saveWorkItem3(workingCopy, null, null, additionalSaveParameters);
System.setProperty(projectArea.getItemId().toString() + " - " + projectArea.getName() + " - " + POOL_DE_ABOGADOS_ANTERIOR, getStringPoolAbogadosActual(aAbogados));
System.setProperty(projectArea.getItemId().toString() + " - " + projectArea.getName() + " - " + ABOGADO_POR_ASIGNAR, getProximoAbogadoPorAsignar(oAbogadoPorAsignar.getItemId().toString(), aAbogados));

I thought that the addtional parameters had an option for not to validate permissions but I think I was wrong.

The field es "abogado" and the following is the error that I'm geting:

Excepción al ejecutar acción subsiguiente. Se ha producido una excepción no manejada durante "Build on State Change".
CRJAZ6053E No se puede completar la operación 'Guardar elemento de trabajo'. Se requiere permiso para completar la operación.

sam detweiler commented Apr 30 '14, 11:18 a.m.

your extension will be called immediately again because of the save.  YOUR code has to check if the extra parameter is passed and behave differently if it is.

if the save parm is not present, then u reject the change if the wrong person is making the change, or allow the change, make the change, cause another save, and then ignore the recursion.

but you might need to do this in two parts.
advisor to prevent wrong user
and participant to set the field.. (and ignore the recursion)

Juan Martín Alberti commented Apr 30 '14, 12:49 p.m.


Thanks for your aswer.

I think you understood me wrong.

The person who is saving has no right to modify the field but the extension must modify the field when that user saves.

I need the extension modify the field when the user that has no right to modify the field is saving. 

sam detweiler commented Apr 30 '14, 2:43 p.m. | edited Apr 30 '14, 2:45 p.m.

yeh, that should be no problem.
you have to allow the operation to execute with permissions even tho you will fix it after the fact.
but your extension will be called again when you DO save the workitem.

note that the field is set wrong before your participant runs.

Be the first one to answer this question!

Register or to post your answer.