Jelly script to retrieve a Date custom field value to Jira.

Vishali
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.
October 9, 2012

Hi,

I have got a custom field 'Expected Start Date' in Jira. I need to get 'Shipping Date' custom field 3 business days prior to 'Expected Start Date'. I have got this working using the below jelly script. I need to get this result date into Jira custom field as an value.

I have tried this but gave an error - Can't convert 28/Sep/12 (Note: this is the value of Shipping date that I need to get to Jira custom field) to interface com.atlassian.jira.issue.fields.CustomField

<core:invoke on="${issueKey}" method="setCustomFieldValue">
<core:arg type="com.atlassian.jira.issue.fields.CustomField" value="${formattedDate}"/>
</core:invoke>

Could someone please help?

*****************************************************************

<JiraJelly xmlns:jira="jelly:com.atlassian.jira.jelly.enterprise.JiraTagLib" xmlns:core="jelly:core" xmlns:log="jelly:log">
<jira:Login username="admin" password="password">


<jira:RunSearchRequest filterid="11113" var="issues"/>

<!-- Get an instance of ComponentManager -->
<core:invokeStatic className="com.atlassian.jira.ComponentManager" method="getInstance" var="componentManager"/>


<!-- Get the IssueManager from ComponentManager -->
<core:invoke on="${componentManager}" method="getIssueManager" var="issueManager"/>


<!-- Get Custom FieldManager from ComponentManager -->
<core:invoke on="${componentManager}" method="getCustomFieldManager" var="customFieldManager"/>


<!-- Get CustomFieldObject from customFieldManager -->
<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="customFieldObj1">
<core:arg type="java.lang.String" value="customfield_10049"/>
</core:invoke>


<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="customFieldObj2">
<core:arg type="java.lang.String" value="customfield_11233"/>
</core:invoke>


<core:invoke on="${customFieldManager}" method="getCustomFieldObject" var="customFieldObj3">
<core:arg type="java.lang.String" value="customfield_11234"/>
</core:invoke>


<!-- The current time -->
<core:invokeStatic className="java.util.Calendar" method="getInstance" var="CalendarField"/>
<core:forEach var="issue" items="${issues}">


<!-- Get the Issue from IssueManager -->
<core:invoke on="${issueManager}" method="getIssueObject" var="issueKey">
<core:arg type="java.lang.String" value="${issue.key}"/>
</core:invoke>


<!-- Get Custom Field Value -->
<core:invoke on="${customFieldObj1}" method="getValue" var="expStartDate">
<core:arg type="com.atlassian.jira.issue.IssueImpl" value="${issueKey}"/>
</core:invoke>


<core:invoke on="${CalendarField}" method="setTime">
<core:arg type="java.sql.Timestamp" value="${expStartDate}"/>
</core:invoke>


<core:invoke on="${CalendarField}" method="get" var="dayOfweek">
<core:arg type="int" value="7"/>
</core:invoke>


<core: set var="ExpDay" value = "${dayOfweek}"/>
<core:choose>
<core:when test="${ExpDay == 2 || ExpDay == 3 || ExpDay == 4 }">
<core:set var="ShipDay" value="${-5}" />
</core:when>
<core:otherwise>
<core:set var="ShipDay" value="${-3}" />
</core:otherwise>
</core:choose>


<core:invokeStatic className="java.util.Calendar" method="getInstance" var="NewCalendarField"/>


<core:invoke on="${NewCalendarField}" method="setTime">
<core:arg type="java.sql.Timestamp" value="${expStartDate}"/>
</core:invoke>


<core:invoke on="${NewCalendarField}" method="add" var="ShipStartDate">
<core:arg type="int" value="7"/>
<core:arg type="int" value="${ShipDay}" />
</core:invoke>


<core:invoke on="${NewCalendarField}" method="getTime" var="ShippingDate"/>


<core:new className="java.text.SimpleDateFormat" var="format">
<core:arg type="java.lang.String" value="dd/MMM/yy"/>
</core:new>


<core:invoke on="${format}" var="formattedDate" method="format">
<core:arg type="java.util.Date" value="${ShippingDate}" />
</core:invoke>

</core:forEach>
</jira:Login>
</JiraJelly>

1 answer

2 votes
David Pinn
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.
June 4, 2013

You need to call

CustomField#updateIssue(FieldLayoutItem fieldLayoutItem, MutableIssue issue, Map fieldValueHolder)

Vishali
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.
June 5, 2013

David,

Thank you so much for your answer. I figured it out later from other post and added it for my script to work.

Thanks,

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events