It's all about the answers!

Ask a question

Work items: changing it's own attributes when saved (follow up - participant)

Carlos Benavides (132) | asked Jun 14 '17, 1:01 p.m.

Hi guys,

After completing some RSjazz tutorials and participants examples I ended up developing a participant that can get the value from some custom attributes from a parent and set them to all his children. This works when I save the parent.

But now I need something different: get the values from some custom attributes from a parent and set them to a  child but it needs to work when saving this child.

I have this piece of code:

List<IReference> parent_reference = getParentReference(saveParameter);
IAuditable auditable = saveParameter.getNewState();
IWorkItem child_me = (IWorkItem) auditable;
if (!parent_reference.isEmpty()) {
  for (IReference reference: parent_reference ) {
     if (reference.isItemReference()) {
        IItemHandle referencedItem= ((IItemReference) reference).getReferencedItem();
            if (referencedItem instanceof IWorkItemHandle) {
                IWorkItem parent = (IWorkItem) auditableCommon
                .resolveAuditable((IWorkItemHandle) referencedItem
                , IWorkItem.FULL_PROFILE, null);
                IAttribute fecha_para_el_plugin_Attribute_parent_only = wiCommon
                , WORKITEM_ATTRIBUTE_FECHA_PARA_EL_PLUGIN, monitor);
                IAttribute enumeracion_para_el_plugin_Attribute_parent_only = wiCommon
                Object fecha_para_el_plugin_parent_only =  
                Object enumeracion_para_el_plugin_parent_only =
                child_me = (IWorkItem)child_me.getWorkingCopy();
                IAttribute fecha_para_el_plugin_Attribute_parent_only_child = wiCommon
                , WORKITEM_ATTRIBUTE_FECHA_PARA_EL_PLUGIN, monitor);

                IAttribute enumeracion_para_el_plugin_Attribute_parent_only_child = wiCommon
                , fecha_para_el_plugin_parent_only);

                , enumeracion_para_el_plugin_parent_only);
                Set<String> additionalParams = new HashSet<String>();

What this code does is:
After saving a work item, the participant looks if it has a parent. If True then it gets the value from "fecha_para_el_plugin_Attribute_parent_only" and "enumeracion_para_el_plugin_Attribute_parent_only_child" attributes from the parent.

Once I have these values I need to set them to the child (the work item which is saving) so I´m using this code:

, fecha_para_el_plugin_parent_only);
, enumeracion_para_el_plugin_parent_only);

But for some reason It's not working. I'm still seeing empty fields in the child. I even tried to see the values from these attributes from the child using message boxes (to confirm if ".setValue" works) and it worked fine, but when the "save operation" is completed these attributes returns to "none" or empty. I don't know why.

Am I using the wrong code (".setValue")?
Am I missing a code?

Please I need help on this because I think it could be solved easily.

Thank you!

One answer

permanent link
Ralph Schoon (63.2k33646) | answered Jun 14 '17, 2:50 p.m.

Debugging should easily show if the code is executed and values are set. Key here is to understand debugging on Jetty as explained in the extensions workshop. If you can debug, you can observe what happens and what does not.

In addition, you actually might want to issue a save of the work items with the chaged attributes. So I  am kind of missing

  • IWorkItemServer.saveWorkItem3(),
  • IWorkItemServer.saveWorkItem2() or
  • IWorkItemServer.saveWorkItems()
In the code, which is quite essential if you actually want to persist changes.......

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.