Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Parse Long to date format Scriptrunner

Hello together,

I want to build a sum of a customfield with date format and a customfield with double format (count of days). 

I want to build a sum of both which should be in date format. So I only want to add value of the double formatted field to the customfield with date format. 

 

How is this possible? 

Thank you guys.

 

2 answers

1 accepted

Hi @Tobias

For your requirement, I would suggest using the Scripted Field. The Scripted Field can be used to perform the calculation of the Date custom field with the Number field and provide the output, i.e. the new date in date format.

You can follow the steps below to create it.

First, add two custom fields, one for the Date field and one for the Number field, as shown in the print screen below:-

image1.png

 

Next, go to ScriptRunner's Fields option and click on the Create button as shown below:-

image2.png

 

Once you have clicked on the create button, select the Custom Script Field as shown in the image below:-

image3.png

After you have selected the Custom Script Field option, you will need to provide a Field Name for it and also select the Template to Date as shown below:-

image4.png

Now, you will need to include the Script. Below is a sample script for your reference:-

import com.atlassian.jira.component.ComponentAccessor

def customFieldManager = ComponentAccessor.customFieldManager

def originalDate = customFieldManager.getCustomFieldObjectsByName("Original Date")[0]
def originalDateValue = originalDate.getValue(issue) as Date

def additionalDays = customFieldManager.getCustomFieldObjectsByName("Additional Days")[0]
def additionalDaysValue = additionalDays.getValue(issue) as Integer

return (originalDateValue + additionalDaysValue) as Date

Please note, this sample script is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below is a print screen of the Scripted Field with the code:-

image5.png

After adding the code, you can save it.

Below are some print screens of a test:-

image6.png

For this example, the Original Date selected is 14th May 2021 and the Additional days entered are 7, so the expected result in the Scripted Field is 21st May 2021.

image7.png

In the print screen above, the Updated Date, i.e. the Scripted Field, is set to 21st May 2021 as expected.

I hope this helps to answer your question. :)

Thank you and Kind regards,

Ram

 

 

Hi @Ram Kumar Aravindakshan _Adaptavist_
thanks for your reply. 

This looks really good for calculating with days. 

In my case I had to calculate with months and I also want to share my source code with you.

import org.apache.commons.lang.time.DateUtils
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue;

def cfIntervall = ComponentAccessor.customFieldManager.getCustomFieldObject(13022)
def cfFreigabe = ComponentAccessor.customFieldManager.getCustomFieldObject(15024)

if (cfIntervall && cfFreigabe && issue.getCustomFieldValue(cfIntervall) && issue.getCustomFieldValue(cfFreigabe))
{
def intMonths = issue.getCustomFieldValue(cfIntervall) as Integer;
def newRevision=DateUtils.addMonths((Date) cfFreigabe.getValue(issue),intMonths)
return newRevision
}
else
{
return null;
}

Maybe someone has the same problem like me.

But thank you for your reply, works also.  

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

New cloud apps roundup - June 2021

Since our last roundup in April, Atlassian's Marketplace Partners have added over 100 new cloud apps to the Atlassian Marketplace to help your teams work more efficiently. Let’s take a quick look a...

355 views 5 10
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you