Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Reading from screen fields

Dimitris Xernos April 1, 2012

Hi.

I have developed a plugin with a listener which is able to catch the events fired in JIRA.

I want when special events are fired, to read the values of specific fields of a screen and pass them to an external database.

I haven't found any documentation about how I could the read the values from the fields of a screen.

Can you guide what classes I could use for this ?

Thanks for your help.

Dimitris

1 answer

0 votes
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.
April 1, 2012

Hi, you can use change items to detect fields.

try {
	// Read change items, comment 
	List<GenericValue> changeItems = event.getChangeLog().getRelated("ChildChangeItem");
	Comment comment = event.getComment();
					
	String field, fieldType; 
	for (GenericValue changeItem : changeItems) {
		fieldType = (String) changeItem.get("fieldtype");
		field = (String) changeItem.get("field"); // Field Name
		// Collection of all fields with the same name!
		Collection<CustomField> cfCol = Helper.getCustomFieldByName(field);
		// ...
					
		// Detect attachment
		if (Constants.CHANGE_ITEM_FIELD_TYPE_JIRA.equalsIgnoreCase(fieldType) && // JIRA
			Constants.CHANGE_ITEM_FIELD_ATTACHMENT.equalsIgnoreCase(field)) {	 // Attachment
						
			Object attachmentId = changeItem.get("newvalue");
			if (attachmentId != null && attachmentId.toString().length()>0) {
				// Attachment Add
				try {
					Attachment attachment = ComponentAccessor
						.getAttachmentManager().getAttachment(Long.valueOf(attachmentId.toString()));
					// Action
				}
				catch (DataAccessException dae) {
					error("Unable to access attachment with id:" + attachmentId.toString() + "!", dae);
				}
			}
			else {
				// Attachment Delete, no WS interface method
				attachmentId = changeItem.get("oldvalue");
				debug("Attachment with id:" + attachmentId.toString() + " delete action is not sychronized.");
			}
		}
		else {
			// Read value from changed field + operation					
		}
	}
} catch (GenericEntityException gee) {
	log.error("Can not read change items list!", gee);
}

Dimitris Xernos April 2, 2012

Hi.

Thanks for your response.

The problem with the solution you describe is that I catch only the fields with changed content. What I want to do is to develop a workflow where the at the first step the issue creator will fill a screen with data. At the final step of the workflow, before the case is closed, I want my listener to be able to read the data from the screen and store them to a external database. The data of the screen may be the same with data that the issue creator filled at first step of the workflow.

Dimitris

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.
April 2, 2012

So you need post function (not the listener) and add this function into the last workflow step. Function wiil be read issue content and call methods to update external DB.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events