Converting types using Jelly

Platform Notice: Data Center Only - This article only applies to Atlassian products on the Data Center platform.

Note that this KB was created for the Data Center version of the product. Data Center KBs for non-Data-Center-specific features may also work for Server versions of the product, however they have not been tested. Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Symptoms

When programming in Jelly, the following code snippet might be used:

1 2 3 4 5 6 7 8 9 10 11 <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:

1 2 3 4 5 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.

Resolution

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...

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

... with this...

1 <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:

1 2 3 4 5 <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:

Updated on April 8, 2025

Still need help?

The Atlassian Community is here for you.