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

How to show option values of custom select field in velocity template

MuhammadU September 15, 2013

I want to retrieve all options of a select custom field. See my code below, I can get the custom field but not able to show its options .. :(

#set ( $c_n = $customFieldManager.getCustomFieldObjectByName("Deptt") )
$c_n.getIdAsLong()
#set ( $opts = $c_n.getOptions() )

<ul>
  #foreach( $opt in $opts )
    <li>$opt.getValue()</li>
  #end
</ul>

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Bharadwaj Jannu
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.
September 16, 2013

hello Muhammed Usman,

you can directly use $configs variable to get the options for that context.

for reference read

and might be #foreach ($option in $configs.options) work to display options.

MuhammadU September 16, 2013

Hi Bharadwaj,

Thanks for your reply. I cannot make it work.

I am using this code now, what am I missing?

#set ( $c_n = $customFieldManager.getCustomFieldObjectByName("Customer Name") )
<ul>
  #foreach ($option in $configs.options)
    <li>$option.value</li>
  #end
</ul>

MuhammadU September 16, 2013

I am using it in Project Tab Panel template.

Bharadwaj Jannu
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.
September 16, 2013

ok, but where exactly you want to retrieve the options. I mean in which context the template is used.

Bharadwaj Jannu
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.
September 16, 2013

which mean you are trying to display the contents of CustomerName as select list in Project Tab Panel?

MuhammadU September 16, 2013

not as a select list though. I just want to show these like this:

Department Name:

- Dept 1

- Dept 2

Customer Name:

- Customer Name 1

- Customer Name 2

Bharadwaj Jannu
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.
September 16, 2013

do you have issue object as a variable in your hand?

MuhammadU September 16, 2013

No.. I dont have issue object .. I have added new project tab panel named departments .. and on that page I want to show all departments assoicated with the project ( which is available in deptt custom field )...

Bharadwaj Jannu
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.
September 16, 2013

in that case configs.options will not work.

you create JiraContextTreeManager object in your java class, using that get JiraContextNode object and store in some variable. Pass this variable to your vm file. Now you have JiraContextNode in your hand.

probably you might get options using

$customFieldManager.getCustomFieldObjectByName("Deptt").getOptions(null,/*variable that stored JiraContextNode object*/)

MuhammadU September 16, 2013

So there is no way except creatiung a new class for project tab panel and then passing variables like you mentioned. ?

Bharadwaj Jannu
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.
September 16, 2013

I think no need of creating a new java class, you already might have written class for your Project Tab Panel, in that class itself you try to put the value in the map variable.

I found the following code that pass some values to variables in Version Project Tab Panel

protected Map<String, Object> createVelocityParams(BrowseContext ctx)

{

Project project = ctx.getProject();

List versions = getVersions(project);

Map params = super.createVelocityParams(ctx);

params.put("versionsCount", Integer.valueOf(versions.size()));

Integer subset = getSubset();

Collection versionToDisplay = TabPanelUtil.subSetCollection(versions, subset.intValue());

params.put("versions", versionToDisplay);

params.put("hasAdminPermission", this.permissionHelper.hasProjectAdminPermission(this.authenticationContext.getLoggedInUser(), project));

params.put("showingAll", Boolean.valueOf(versions.size() < 20));

params.put("subset", subset);

params.put("dateFieldFormat", this.dateFieldFormat);

return params;

}

MuhammadU September 16, 2013

Thanks. You have been so helpful .. :) .. This solves my problem ..

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.
September 16, 2013

Line 2 is breaking what you're doing for a start!

MuhammadU September 16, 2013

Thanks, Parameters is the issue.

BUT How we can get these parameters in velocity

getOptions(String key, JiraContextNode jiraContextNode)

TAGS
AUG Leaders

Atlassian Community Events