notification when i add file in an issue

Jerome Martin December 12, 2012

Hi

Is it possible to send a notification when i add a file in an issue ?

thanks

2 answers

1 accepted

2 votes
Answer accepted
Radek Kantor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 18, 2012

Hi,

according me it is impossible detect only attach file action. "Issue updated" event is fired for every action, that change issue. So your email notification will be trigered also by any field value change, comment added, not only for file added action.

If you dont find any plugin/existing solution for this, you probably must write own custom issue event listener and handle only file attach operation. Realize this as plugin or maybe by groovy script.

https://developer.atlassian.com/display/JIRADEV/Writing+JIRA+event+listeners+with+the+atlassian-event+library

To recognize, that file was added, list change items and find field type and name for attachment, more:

@Override
	public void issueUpdated(IssueEvent event) {
        try {
            // Read change items
            GenericValue genericValue = event.getChangeLog();
            if (genericValue == null) {
                return;
            }
            List<GenericValue> changeItems = genericValue.getRelated("ChildChangeItem");
            String fieldName, fieldType;
            for (GenericValue changeItem : changeItems) {
                fieldType = (String) changeItem.get("fieldtype");
                fieldName = (String) changeItem.get("field");
                // Detect attachment
                if ("JIRA".equalsIgnoreCase(fieldType) && IssueFieldConstants.ATTACHMENT.equalsIgnoreCase(fieldName)) {
                    Object attachmentId = changeItem.get("newvalue");
                    if (attachmentId != null && attachmentId.toString().length()>0) {
                        try {
                            Attachment attachment = ComponentAccessor.getAttachmentManager().getAttachment(Long.valueOf(attachmentId.toString()));
                            // TODO Execute code
                        }
                        catch (DataAccessException dae) {
                            error("Unable to access attachment with id:" + attachmentId.toString() + "!", dae);
                        }
                    }
                    else {
                        // Attachment Delete, no action
                    }
                    return;
                }
            }
        } catch (GenericEntityException gee) {
            log.error("Can not read change items list!", gee);
        }
	}

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 12, 2012

That fires an "issue updated" event - just modify your notification scheme to send to the people who need to know an attachment has been added.

Jerome Martin December 17, 2012

Hi Nic

Thank you for your answer but i don't find where, in the notification scheme, i could modify something to send to the people a notification. It seems, there isn't notification for that in the scheme. How do you do that ?

Radek Kantor
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 18, 2012

First add new event, use template "Issue Updated", than in your notification scheme assign some email recipients/notifications for new event. Or if there already exists default system "Issue Updated" event, only update this one.

Jerome Martin December 18, 2012

@Radek

Hi radeK
it's ok scheme notification are correctly setup and the template is associated with a scheme notification ( advanced -> events)

Renjith Pillai
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
December 25, 2012

Jerome,

What is that you are looking for? Are you able to refer to this doc about configuring notifications - https://confluence.atlassian.com/display/JIRA/Creating+a+Notification+Scheme ?

Suggest an answer

Log in or Sign up to answer