Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

unable to use custom-field for user picker

dhaval soni
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.
May 12, 2013

Hi

I have created a screen thorugh webwork module where i need to allow the users to select jira users. So, instead of querying to database and fetch the users, it would be easy if i can use any default feature from JIRA.

I have added below custom field into atlassian-plugin.xml

<customfield-searcher key="userpickersearcher" name="User Picker Searcher"
        i18n-name-key="admin.customfield.searcher.userpickersearcher.name"
        class="com.atlassian.jira.issue.customfields.searchers.UserPickerSearcher">
        <description key="admin.customfield.searcher.userpickersearcher.desc">Allow to search for a user using a userpicker.</description>
        <resource type="velocity" name="label" location="templates/plugins/fields/view-searcher/label-searcher-user.vm"/>
        <resource type="velocity" name="search" location="/templates/UserDa.vm"/>
        <resource type="velocity" name="view" location="templates/plugins/fields/view-searcher/view-searcher-basictext.vm"/>
        <valid-customfield-type package="com.atlassian.jira.plugin.system.customfieldtypes" key="userpicker"/>
        <valid-customfield-type package="com.atlassian.jira.plugin.system.customfieldtypes" key="multiuserpicker"/>        
    </customfield-searcher>

In above code, "UserDa.vm" file is used in my webwork module screen. ("<resource type="velocity" name="search" location="/templates/UserDa.vm"/>") All other template mentioned for "View", "label" resources, i have not created, i believe, those will be found from default JIRA template location. below is "UserDa.vm" file's body part:

&lt;body&gt;

 &lt;div class="ajax_autocomplete" id="searcher-${customField.id}_container"&gt;
		        &lt;fieldset rel="${customField.id}" class="hidden user-searcher-params"&gt;
		            &lt;input title="formName" type="hidden" value="issue-filter" /&gt;
		            &lt;input title="fieldName" type="hidden" value="${customField.id}" /&gt;
		            &lt;input title="fieldId" type="hidden" value="searcher-${customField.id}" /&gt;
		            &lt;input title="multiSelect" type="hidden" value="false" /&gt;
		            #if ($canPerformAjaxSearch)&lt;input title="userPickerEnabled" type="hidden"value="true" /&gt;#end
		        &lt;/fieldset&gt;
		        &lt;input class="text" id="searcher-${customField.id}" name="${customField.id}" type="text" value="$textutils.htmlEncode($!value)" /&gt;
		        #if ($action.isHasPermission("pickusers"))
		            &lt;a class="user-popup-trigger" href="#" id="searcher-${customField.id}Image"&gt;&lt;img title="${i18n.getText('navigator.filter.userpicker.imagetitle1')}" name="${customField.id}Image"  src="${baseurl}/images/icons/filter_public.gif" hspace="0" height="16" width="16" border="0" align="absmiddle" /&gt;&lt;/a&gt;
		        #end
		        &lt;div class="description" id="searcher-${customField.id}_desc" style="display:none;"&gt;${i18n.getText('user.picker.ajax.desc')}&lt;/div&gt;
    		&lt;/div&gt;	

.....
..
.
&lt;/body&gt;

Now, over the screen, i found, textbox appear and users icon at beside of textbox but,it does not popup for users list and also, textbox does not show user intelligence for autocomplete feature so, it is not working.

Can you share me what does i miss here ?

i found above custom field at,

https://confluence.atlassian.com/display/JIRA043/Custom+Field+Plugin+Module

Any one plz share documentation or stuff which can resolve the issue and allow to populate userlist.

Thank You

4 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

2 votes
Answer accepted
Tibor Hegyi _META-INF_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 14, 2013

hi,

I have just added the below snippet to a plugin and it works as expected.

Replace "myFieldId" with anything you like or leave it as is. Note, if you want to have a different name, you must replace it everywhere in the HTML structure below.

&lt;fieldset rel="myFieldId" class="hidden user-picker-params"&gt;
	&lt;input type="hidden" id="formName" value="jiraform"&gt;
	&lt;input type="hidden" id="fieldName" value="myFieldId"&gt;

	&lt;input type="hidden" id="multiSelect" value="true"&gt;
	&lt;input type="hidden" id="userPickerEnabled" value="true"&gt;
&lt;/fieldset&gt;
&lt;div class="ajax_autocomplete" id="myFieldId_container"&gt;
	&lt;input type="text" name="myFieldId" id="myFieldId" value="" class="userpickerfield text" /&gt;
	&lt;a class="popup-trigger" href="#"&gt;&lt;img title="Select a user(s)" name="multiuserImage" src="${req.contextPath}/images/icons/filter_public.gif" hspace="0" height="16" width="16" border="0" align="top" /&gt;&lt;/a&gt;
	&lt;br/&gt;&lt;div id="myFieldId_results" class="ajax_results"&gt;&lt;/div&gt;
	&lt;div class="description"&gt;$action.i18n.getText("issuemail.form.userpicker.desc")&lt;/div&gt;
&lt;/div&gt;

dhaval soni
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.
May 14, 2013

Excellent !

it works..

how can i convert it to single user selecting on popup and textbox.

i want only single user selection.. no need for multi user here.

1 vote
Tibor Hegyi _META-INF_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 13, 2013

Hey, you cannot comment out velocity code with html comment markup <!-- -->

Replace #if($action.hasBrowseUserPermission) with

## #if($action.hasBrowseUserPermission)

Inline Velocity comments start with "##".


dhaval soni
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.
May 13, 2013

Thanks, now i got appear "textbox" and user icon.

But it does not populate user list.

here, myFieldId, i have just given - "userpicker" which is same as "customfield" key in atlassian plugin. is it correct or else have to put.

have not added any class, just updated atlassian plugin to include stuff and updated HTML file only.

dhaval soni
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.
May 13, 2013

now, i am going through without autocomplete feature. plz let me know what would be the cause or missing in stuff for above issue.

0 votes
Tibor Hegyi _META-INF_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 13, 2013

In order to make the user picker work in your screen, you don't need to add the customfield-searcher component to atlassian-plugin.xml.

You need to:

- configure the HTML code correctly

- add a webresource element to atlassian-plugin.xml with context and dependency:

<context>jira.general</context>

<dependency>jira.webresources:jira-global</dependency>

<dependency>jira.webresources:autocomplete</dependency>

I think you HTML code is not correct to get a user picker field working. You need something like

&lt;fieldset rel="myFieldId" class="hidden user-picker-params"&gt;
&lt;input type="hidden" id="formName" value="jiraform"&gt;
&lt;input type="hidden" id="fieldName" value="myFieldId"&gt;

&lt;input type="hidden" id="multiSelect" value="true"&gt;
&lt;input type="hidden" id="userPickerEnabled" value="true"&gt;
&lt;/fieldset&gt;
&lt;div class="ajax_autocomplete" id="myFieldId_container"&gt;
#if($action.hasBrowseUserPermission)
&lt;input type="text" name="myFieldId" id="myFieldId" value="" class="userpickerfield text" /&gt;
&lt;a class="popup-trigger" href="#"&gt;&lt;img title="Select a user(s)" name="multiuserImage" src="${req.contextPath}/images/icons/filter_public.gif" hspace="0" height="16" width="16" border="0" align="top" /&gt;&lt;/a&gt;
#end
&lt;br/&gt;&lt;div id="myFieldId_results" class="ajax_results"&gt;&lt;/div&gt;
&lt;/div&gt;

Where "myFieldId" is the unique name or id of your field.

Tibor

dhaval soni
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.
May 13, 2013

Hi,

I have removed customfield searcher in and kept only - customfield-type element as before. and Added below resource element:

&lt;web-resource name="general Jira Resources" key="GeneralJIRAresources"&gt;  	 
    &lt;context&gt;jira.general&lt;/context&gt;
  	&lt;dependency&gt;jira.webresources:jira-global&lt;/dependency&gt;
  	&lt;dependency&gt;jira.webresources:autocomplete&lt;/dependency&gt;
  &lt;/web-resource&gt;

in html, added below stuff:

&lt;div&gt;
			&lt;fieldset rel="userpicker" class="hidden user-picker-params"&gt;
				&lt;input type="hidden" id="formName" value="jiraform"&gt;
				&lt;input type="hidden" id="fieldName" value="myFieldId"&gt;
 
				&lt;input type="hidden" id="multiSelect" value="true"&gt;
				&lt;input type="hidden" id="userPickerEnabled" value="true"&gt;
			&lt;/fieldset&gt;
			&lt;div class="ajax_autocomplete" id="userpicker_container"&gt;
			&lt;!--	#if($action.hasBrowseUserPermission) --&gt;
					&lt;input type="text" name="myFieldId" id="userpicker" value="" class="userpicker" /&gt;
					&lt;a class="popup-trigger" href="#"&gt;&lt;img title="Select a user(s)" name="multiuserImage" src="${req.contextPath}/images/icons/filter_public.gif" hspace="0" height="16" width="16" border="0" align="top" /&gt;&lt;/a&gt;
				&lt;!-- #end--&gt;
				&lt;br/&gt;
				&lt;div id="userpicker_results" class="ajax_results"&gt;&lt;/div&gt;
			&lt;/div&gt;
		&lt;/div&gt;

now, it does not appear me input textbox . what is miss here.

Do i need to link some where template and custom field or include web-resource at page level or any other thing?

Thanks

0 votes
Tibor Hegyi _META-INF_
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
May 12, 2013

Hi, why do you add this custom field to your plugin? Do you want to customize it? Your code looks like the custom field that is available in JIRA out-of-box, so normally you do not add it to your plugin but use it in JIRA.

User picker fields have complex HTML structures they are not a simple input text. You can look at macros.vm in directory WEB-INF/classes/templates/plugins/jira.

search for the macro "userPicker" to see the velocity snippet that generates the HTML code for user picker fields.

As you can see there you'll have to add couple of divs and a fieldset tag to define all DOM elements needed.

Study this file and add all necessary elements to the vm file in your plugin.

Tibor

dhaval soni
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.
May 13, 2013

I have updated original question. Also, i tried as you suggested.

But looks like, i miss some stuff. so, it is not working.

Can you please look at orignal question, i have updated the current status of stuff and description.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events