It's all about the answers!

Ask a question

Why custom plugin is not execute when Filed Against is Unassigned on implicit save of attachment?


Asha Faldu (1110) | asked Jun 23 '17, 7:54 a.m.

 Hello All,


When I attach an attachment to the Workitem and Filed Against value is Unassigned then on implicit save of attachment (Note : Workitem save is not clicked) custom plugins is not executed But when the value of Filed Against is category type then custom plugin is execute on implicit save of attachment.

For Example :

Team_COSI is Team Area
Category is COSI mapped with Team_COSI team Area

Filed Against = Unassigned and attaching an attachment then custom plugin is not executing on implicit save by attachment 

Filed against = COSI and attaching an attachment then custom plugin is executing on implicit save by attachment 

Why plugins is behaving like this?

One answer



permanent link
Ralph Schoon (63.3k33646) | answered Jun 23 '17, 8:04 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
edited Jun 23 '17, 9:14 a.m.
Apparently your extension is doing it right. Since some version when attaching a file to a work item calls the work item save operation with an IAttachment in the data. This only happens during a safe in the Web UI if there is a category set. 

Independent of what these values are (I don't know why it was implemented like this), it is up to you to make sure to not run in your code, if not needed. For example, in this specific case, the data you get is an IAttachment or something. So you have to check that you only run your code, if the correct class/interface is passed and you can safely cast it to what you need.


So check the data and exit your extension if it does not match what you need and exit. I think that is what your code, correctly, does.  


Comments
Ralph Schoon commented Jun 23 '17, 8:27 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

This code prevents the wrong operation, I think

        /
         * First check that the operation data is work item save data.
         /
        Object data = operation.getOperationData();
        ISaveParameter saveParameter = null;
        /
         * If there is no data or the data is not of the required type or 
         * If the state id has not changed, do not build.
         /
        if (data != null && data instanceof ISaveParameter) {
            saveParameter = (ISaveParameter) data; // Get the data
            if (!(saveParameter.getNewState() != null && saveParameter.getNewState() instanceof IWorkItem)) {
                return; // This is not a new work item state to check against e.g. save attachment in the Web UI
            }
            Identifier<istate> oldStateId = null; // New work item check.
            if (saveParameter.getOldState()!= null && saveParameter.getOldState() instanceof IWorkItem) {
                IWorkItem oldState = (IWorkItem) saveParameter.getOldState(); // The old state is a work item
                oldStateId = oldState.getState2(); // Get the old state
            }
            IWorkItem newState = (IWorkItem) saveParameter.getNewState();
            Identifier<istate> newStateId = newState.getState2();
            if ((newStateId != null) && !(newStateId.equals(oldStateId))) {

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.