Forums

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

How to use API save value for a custom field of ReadOnlyCFType

Deleted user April 16, 2012

I am upgrading a plugin to make it comptable with Jira 5.0.2.

The plugin will save the previous assignee to a custom field in issue in listener method.

The code is as follow:

Issue issue = event.getIssue();
String assigneeName = getPreviousAssigneeValue(event);
customField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(customField), assignee), new DefaultIssueChangeHolder());

The getPrevisouAssigneeValue(event) can return the correct User name as String type.

But the customField.updateValue does not work.

Can any body help me?

And the implementation of the customfield type is

public class PreviousAssigneeCFType extends ReadOnlyCFType {
	private final UserManager userMgr;

	public PreviousAssigneeCFType(UserManager userMgr,
			CustomFieldValuePersister customFieldValuePersister,
			StringConverter stringConverter,
			GenericConfigManager genericConfigManager) {
		super(customFieldValuePersister, stringConverter, genericConfigManager);
		this.userMgr = userMgr;
	}

	public String getSingularObjectFromString(final String string)
			throws FieldValidationException {
		return userMgr.getUser(string).getName();
	}
}

Thanks & Regards,

Yaoyu

1 answer

1 accepted

0 votes
Answer accepted
Jobin Kuruvilla [Adaptavist]
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 16, 2012

Can you try this?

Issue issue = event.getIssue();
FieldLayoutManager fieldLayoutManager = ComponentAccessor.getFieldLayoutManager();
FieldLayoutItem fieldLayoutItem = fieldLayoutManager.getFieldLayout(issue).getFieldLayoutItem(customField);
String assigneeName = getPreviousAssigneeValue(event);
customField.updateValue(fieldLayoutItem, issue, new ModifiedValue(issue.getCustomFieldValue(customField), assignee), new DefaultIssueChangeHolder());

Deleted user April 17, 2012

My plugin records the previous assignee of issue. now it works in issue, the previous assignee can be recorded.

But for search, the condition cannot search issue out. please help instruct which issue searcher should be configed.

The cftype java:

public class PreviousAssigneeCFType extends ReadOnlyCFType {
	
	private final UserManager userMgr;
	
	PreviousAssigneeCFType(CustomFieldValuePersister customFieldValuePersister, GenericConfigManager genericConfigManager, UserManager userMgr) {
		super(customFieldValuePersister, genericConfigManager);
		this.userMgr = userMgr;
	}

	public String getSingularObjectFromString(final String string) throws FieldValidationException {
		User user = userMgr.getUser(string);
		if(user!=null){
			return user.getName();
		}
		return "";
	}
	
}

The issue searcher config in atlassian.xml:

<customfield-searcher key="previous-assignee-searcher"
		name="Previous Assignee Searcher"
		class="com.atlassian.jira.issue.customfields.searchers.TextSearcher">
		<description>Search for an issue's previous assignee</description>
		<resource type="velocity" name="label"
			location="templates/plugins/fields/view-searcher/label-searcher-basictext.vm" />
		<resource type="velocity" name="search"
			location="templates/plugins/fields/edit-searcher/search-basictext.vm" />
		<resource type="velocity" name="view"
			location="templates/plugins/fields/view-searcher/view-searcher-basictext.vm" />
		<valid-customfield-type key="previous_assignee" />
	</customfield-searcher>

neither TextSearcher nor UserPickerSearcher can work.

Please further help on this problem, how can I fix this plugin to support the customfield in issue search filter.

Thanks in advance,

Yaoyu

Jobin Kuruvilla [Adaptavist]
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 17, 2012

When you say the searcher don't work, what do you mean? Have you added the searcher for custom field?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events