Hi
I am trying to set a component on an issue using Jelly, I have tried this but it doesnt work:
<core:set var="componentToAdd" value="OPS" />
<core:invoke on="${issueKey}" method="getComponents" var="components" />
<core:invoke on="${components}" method="add" var="flag">
<core:arg type="org.ofbiz.core.entity.GenericValue" value="${componentToAdd}" />
</core:invoke>
<core:invoke on="${issueKey}" method="setComponents">
<core:arg type="java.util.Collection" value="${components}" />
</core:invoke>
But I get the following error:
org.apache.commons.jelly.JellyTagException: null:30:0: Can't convert OPS to class org.ofbiz.core.entity.GenericValue
How would i set a component into the collection in jelly?
After a lot of slogging I got this working well :) see below in bold for this issue!! I have pasted my whole script here in case anyone else has use for it, it covers a lot of jelly questions. Ths script goes through and sets the jira components of an issue based on a custom field component (each issue type has their own component list).
<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log">
<!-- This should be copied on to the jira server in <jira-application-dir>/WEB-INF/classes (/opt/atlassian/jira/atlassian-jira/WEB-INF/classes) and in the same location create a jelly-support-component-set.log file -->
<jira:Login username="support.admin" password="$upp0rt">
<!-- The Support No Component filter -->
<core:set var="supportNoComponentFilter" value="13712"/>
<core:set var="componentCommentFail"
value="Support Auto Admin could not automatically associate this issue to a component, the support consultant dealing with this issue will resolve this with the Support Manager."/>
<core:set var="componentCommentSuccess"
value="Support Auto Admin has assigned this issue to component:"/>
<!-- Get an dispatch option for an issue DO_NOT_DISPATCH ISSUE_UPDATED -->
<core:getStatic className="com.atlassian.jira.event.type.EventDispatchOption" field="ISSUE_UPDATED" var="dispatchOption"/>
<!-- Get an instance of ComponentManager -->
<core:invokeStatic className="com.atlassian.jira.ComponentManager" method="getInstance" var="componentManager"/>
<!-- Get an instance of UserManager -->
<core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" method="getUserManager" var="userManager"/>
<!-- Get a user-->
<core:invoke on="${userManager}" method="getUser" var="user">
<core:arg type="java.lang.String" value="support.admin"/>
</core:invoke>
<!-- Get an instance of IssueManager -->
<core:invoke on="${componentManager}" method="getIssueManager" var="issueManager"/>
<!-- Get an instance of CommentManager -->
<core:invoke on="${componentManager}" method="getCommentManager" var="commentManager"/>
<!-- Get an instance of ProjectComponentManager -->
<core:invoke on="${componentManager}" method="getProjectComponentManager" var="projectComponentManager"/>
<!-- Get an instance of CustomFieldManager -->
<core:invokeStatic className="com.atlassian.jira.component.ComponentAccessor" method="getCustomFieldManager" var="customFieldManager"/>
<!-- Get an instance of sub component field -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="subComponentField">
<core:arg type="java.lang.String" value="customfield_10507"/>
</core:invoke>
<!-- Get an instance of oobaAppComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="oobaAppComponentField">
<core:arg type="java.lang.String" value="customfield_10500"/>
</core:invoke>
<!-- Get an instance of msAppComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="msAppComponentField">
<core:arg type="java.lang.String" value="customfield_10502"/>
</core:invoke>
<!-- Get an instance of networkComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="networkComponentField">
<core:arg type="java.lang.String" value="customfield_10503"/>
</core:invoke>
<!-- Get an instance of hardwareComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="hardwareComponentField">
<core:arg type="java.lang.String" value="customfield_10504"/>
</core:invoke>
<!-- Get an instance of telephonyComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="telephonyComponentField">
<core:arg type="java.lang.String" value="customfield_10505"/>
</core:invoke>
<!-- Get an instance of thirdPartyComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="thirdPartyComponentField">
<core:arg type="java.lang.String" value="customfield_10506"/>
</core:invoke>
<!-- Get an instance of serviceRequestComponentField -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="serviceRequestComponentField">
<core:arg type="java.lang.String" value="customfield_10800"/>
</core:invoke>
<!-- Run the Support No Component filter -->
<jira:RunSearchRequest filterid="${supportNoComponentFilter}" var="noComponentIssues"/>
<!-- Loop through the filter results -->
<core:forEach var="noComponentIssue" items="${noComponentIssues}">
<!-- Get an instance of IssueObject -->
<core:invoke on="${issueManager}" method="getIssueObject" var="issueKey">
<core:arg type="java.lang.String" value="${noComponentIssue.key}"/>
</core:invoke>
<core:catch var="JellyTagException">
<!-- Get an instance of oobaAppComponentFieldValue -->
<core:invoke on="${oobaAppComponentField}" method="getValue" var="oobaAppComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${oobaAppComponentFieldValue}"/>
</core:catch>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of msAppComponentFieldValue -->
<core:invoke on="${msAppComponentField}" method="getValue" var="msAppComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${msAppComponentFieldValue}"/>
</core:catch>
</core:if>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of networkComponentFieldValue -->
<core:invoke on="${networkComponentField}" method="getValue" var="networkComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${networkComponentFieldValue}"/>
</core:catch>
</core:if>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of hardwareComponentFieldValue -->
<core:invoke on="${hardwareComponentField}" method="getValue" var="hardwareComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${hardwareComponentFieldValue}"/>
</core:catch>
</core:if>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of telephonyComponentFieldValue -->
<core:invoke on="${telephonyComponentField}" method="getValue" var="telephonyComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${telephonyComponentFieldValue}"/>
</core:catch>
</core:if>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of thirdPartyComponentFieldValue -->
<core:invoke on="${thirdPartyComponentField}" method="getValue" var="thirdPartyComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${thirdPartyComponentFieldValue}"/>
</core:catch>
</core:if>
<core:if test="${incidentComponentValue == null}">
<core:catch var="JellyTagException">
<!-- Get an instance of serviceRequestComponentFieldValue -->
<core:invoke on="${serviceRequestComponentField}" method="getValue" var="serviceRequestComponentFieldValue">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>
<core:set var="incidentComponentValue" value="${serviceRequestComponentFieldValue}"/>
</core:catch>
</core:if>
<core:choose>
<core:when test="${incidentComponentValue.toString().indexOf(',') > -1}">
<core:catch var="JellyTagException">
<!-- Get the component to set from the incident component -->
<core:set var="equalIndex" value="${incidentComponentValue.toString().indexOf('=')}"/>
<core:set var="commaIndex" value="${incidentComponentValue.toString().indexOf(',')}"/>
<core:set var="oComponentToAdd" value="${incidentComponentValue.toString().substring(equalIndex+1,commaIndex+0)}"/>
<core:set var="componentToAdd" value="${oComponentToAdd.toString().trim()}"/>
</core:catch>
<core:catch var="JellyTagException">
<!-- Get the sub - component to set from the incident component -->
<core:set var="subCompLastEqualIndex" value="${incidentComponentValue.toString().lastIndexOf('=')}"/>
<core:set var="subCompBracketIndex" value="${incidentComponentValue.toString().indexOf('}')}"/>
<core:set var="oSubComponentToAdd" value="${incidentComponentValue.toString().substring(subCompLastEqualIndex+1,subCompBracketIndex+0)}"/>
<core:set var="subComponentToAdd" value="${oSubComponentToAdd.toString().trim()}"/>
</core:catch>
</core:when>
<core:otherwise>
<!-- No sub-component set so just extract incident component and code sub-component to None-->
<core:catch var="JellyTagException">
<!-- Get the component to set from the incident component -->
<core:set var="equalIndex" value="${incidentComponentValue.toString().indexOf('=')}"/>
<core:set var="bracketIndex" value="${incidentComponentValue.toString().indexOf('}')}"/>
<core:set var="oComponentToAdd" value="${incidentComponentValue.toString().substring(equalIndex+1,bracketIndex+0)}"/>
<core:set var="componentToAdd" value="${oComponentToAdd.toString().trim()}"/>
</core:catch>
<core:set var="subComponentToAdd" value="None"/>
</core:otherwise>
</core:choose>
<core:choose>
<core:when test="${componentToAdd != null}">
<!-- Get the projectComponent to update the issue with from the projectComponentManager -->
<core:invoke on="${projectComponentManager}" method="findByComponentName" var="projectComponent">
<core:arg type="java.lang.Long" value="${issueKey.project.id}"/>
<core:arg type="java.lang.String" value="${componentToAdd}"/>
</core:invoke>
<!-- Get the components list of the issue to update -->
<core:invoke on="${issueKey}" method="getComponentObjects" var="components"/>
<!-- Add the project component to the list -->
<core:invoke on="${components}" method="add" var="flag">
<core:arg type="com.atlassian.jira.bc.project.component.ProjectComponent" value="${projectComponent}"/>
</core:invoke>
<!-- Set the components list back on to the issue -->
<core:invoke on="${issueKey}" method="setComponentObjects">
<core:arg type="java.util.Collection" value="${components}"/>
</core:invoke>
<core:if test="${subComponentToAdd != null}">
<!-- Update the sub component field -->
<core:invoke on="${issueKey}" method="setCustomFieldValue">
<core:arg type="com.atlassian.jira.issue.fields.CustomField" value="${subComponentField}"/>
<core:arg type="java.lang.Object" value="${subComponentToAdd}"/>
</core:invoke>
</core:if>
<!-- Update and re index the issue -->
<core:invoke on="${issueManager}" method="updateIssue" var="updatedIssue">
<core:arg type="com.atlassian.crowd.embedded.api.User" value="${user}"/>
<core:arg type="com.atlassian.jira.issue.MutableIssue" value="${issueKey}"/>
<core:arg type="com.atlassian.jira.event.type.EventDispatchOption" value="${dispatchOption}"/>
<core:arg type="boolean" value="false"/>
</core:invoke>
<core:invoke on="${commentManager}" method="create" var="comment">
<core:arg type="com.atlassian.jira.issue.MutableIssue" value="${issueKey}"/>
<core:arg type="java.lang.String" value="support.admin"/>
<core:arg type="java.lang.String" value="${componentCommentSuccess} ${componentToAdd}"/>
<core:arg type="boolean" value="false"/>
</core:invoke>
</core:when>
<core:otherwise>
<core:invoke on="${commentManager}" method="getCommentsForUser" var="comments">
<core:arg type="com.atlassian.jira.issue.MutableIssue" value="${issueKey}"/>
<core:arg type="com.atlassian.crowd.embedded.api.User" value="${user}"/>
</core:invoke>
<core:set var="commentedAlready" value="false"/>
<core:forEach var="comment" items="${comments}">
<core:if test="${comment.getBody().equalsIgnoreCase(componentCommentFail)}">
<core:set var="commentedAlready" value="true"/>
</core:if>
</core:forEach>
<core:if test="${commentedAlready.toString().equalsIgnoreCase('false')}">
<core:invoke on="${commentManager}" method="create" var="comment">
<core:arg type="com.atlassian.jira.issue.MutableIssue" value="${issueKey}"/>
<core:arg type="java.lang.String" value="support.admin"/>
<core:arg type="java.lang.String" value="${componentCommentFail}"/>
<core:arg type="boolean" value="false"/>
</core:invoke>
</core:if>
</core:otherwise>
</core:choose>
</core:forEach>
</jira:Login>
</JiraJelly>
Thanks Justin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You could use jira:TransitionWorkflow tag. Create a transition that returns to itself and during the transition you could update the issue component.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
May I suggest using REST API instead? You can check out the PUT method using /rest/api/2/issue/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok i have just tried using string and it works up to a point, it now populates the component collection, but its not setting the component on the issue:
<core:invoke on="${issueKey}" method="getComponents" var="components" />
<core:invoke on="${components}" method="add" var="flag">
<core:arg type="java.lang.String" value="OPS" />
</core:invoke>
<jira:AddComment comment="components ${components}" issue-key="SUP-27096"/>
<core:invoke on="${issueKey}" method="setComponents">
<core:arg type="java.util.Collection" value="${components}" />
</core:invoke>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.