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

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

You need to call

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

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
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

241 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you