Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How calculate number of days between created date a custom date field?

Shah Baloch
Contributor
March 24, 2022

How can I get the number of days between two date fields and add them to a custom field? For example, I have a custom date field "Issue Reported Date" and I will create another custom field "Number of days". I would like to get the number of days between the system field "created" and the custom field "Issue Reported Date". The Issue Report Date is always earlier than the issue-created date.  For example, the Reported date is 03/20/2022, and the Issue was created on 03/24/2022.  Here is another logic:

Issue Reported Date: 03/20/2022
Created: 03/24/2022
Number of days: 4

I would like to have the Number of days custom field on the view screen. I searched in the community and saw some posts but I couldn't understand how it works, not sure it can be a Behaviours script, listener, or something else.

I'll be thankful if someone can help me with this.

2 answers

Suggest an answer

Log in or Sign up to answer
0 votes
Kristian Walker _Adaptavist_
Community Champion
June 29, 2018

Hi Mitch,

I can confirm that your code is from the ScriptRunner for Jira Server plugin and the Jira Cloud version.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.

This is described in more detail in the documentation page located here.

In order to set the version field for an issue inside of a post function on a cloud instance then you will need to use the Run Script post function which is described in the documentation here.

I have created some example code which shows how you can get the set the fix versions on an issue during a post function which can be viewed here. This code will show you how to set versions and can be used to create the script that you require.

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Mitch Kent
Contributor
June 29, 2018

Hi Kristian,

Thanks for your response.

The reason for that is that the cloud version can only make changes to Jira via the Atlassian Rest API's as cloud does not have a Java API like the server version does.


I realise this is the case, but I wrongly presumed the script runner plugin wrapped these things up in its own library - having looked into it more since I realise how wrong this is :)

This does mean that everything will become vastly more complex after this single example, for any future stuff I would like to work on. As such, there is no point in me continuing with the plugin, and have disabled it.

I appreciate your answer, but I wont be able to use or test it, so I can't mark it as correct.

Regards,

Mitch.

0 votes
Alexey Matveev
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 Champions.
June 26, 2018

Hello,

You are writing a script for Scriptrunner for Jira Server Version. You can not use same scripts for Cloud and Server version. Cloud is built upon Rest calls. Kindly have a look at the documentation for ScriptRunner Cloud:

http://scriptrunner-docs.connect.adaptavist.com/jiracloud/

Mitch Kent
Contributor
June 26, 2018

Thanks Alexey.

 

This looks massively more complicated and effort, though I can appreciate the reasons now I've read through the page.

 

I think I'll just delete the plugin.

TAGS
AUG Leaders

Atlassian Community Events