Documentation for JIRA 4.4. Documentation for other versions of JIRA is available too.

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Current »

Scenario

When programming in Jelly, you can get in a situation as illustrated by the following code snippet:

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib" xmlns:j="jelly:core">

<jira:CreateProjectRole name="QARole" description="QA role">
${jelly.role.id} ${jelly.role.name} ${jelly.role.description}
</jira:CreateProjectRole>

<j:set var="qaroleid" value="${jelly.role.id}"/>

<jira:AddPermission schemeId="0" permissions="Edit" type="projectrole" projectroleid= "${qaroleid}"/>

</JiraJelly>

The goal here is to create a new Project Role and then set the appropriate Permissions to it. However, as the projectroleid and qaroleid variables are have not the same type, you should get an error like this:

Could not run script.
Extra Information: [hide]
Error: <JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.JiraTagLib" xmlns:j="jelly:core">10010 QARole QA role
Exception: org.apache.commons.jelly.JellyTagException: null:10:0: Cannot assign value of type 'java.lang.Long' to property 'projectroleid' of type 'java.lang.String'
java.io.PrintWriter@334cee

So qaroleid, which received a java.lang.Long value from the jelly.role.id context variable, should be converted to a java.lang.String type so it can be informed as projectroleid attribute when setting a Permission.

Problem

How can you convert types in Jelly?

Solution

You can use the invoke Jelly tag to call the method toString on the jelly.role.id context variable and store this value the in the qaroleid variable. So you should replace this line...

<j:set var="qaroleid" value="${jelly.role.id}"/>

... with this...

<j:invoke on="${jelly.role.id}" method="toString" var="qaroleid"/>

... and the script will work sucessfully.

You can also (just as an example matter) use the new Jelly tag to convert the java.lang.String value of the qaroleid variable into a java.lang.Float value and store it in the qafloatvar variable, as shown here:

<j:invoke on="${jelly.role.id}" method="toString" var="qaroleid"/>

<j:new var="qafloatvar" className="java.lang.Float">
<j:arg type="java.lang.String" value="${qaroleid}" />
</j:new>

You may find useful to look at these pages for more information on Jelly tags:

  • No labels