"Add Post Function To Transition applicable that We can report for the number of days between the creation date and the closed date."

Hi,

We want to add Post Function To Transition applicable that we can report  for the number of days between the creation date and the closed date.

Detail:  Calculation (Current Day Time - ) 

Refer to target spot: 

I want to know how to configure by "ScriptRunner for JIRA" installed.

Best Regards,

Pabayos Alaine

1 answer

  1. Create a scripted field
  2. Place a code for scriptRunner to calculate requared value. Somethink like this:

    import com.atlassian.jira.component.ComponentAccessor
    import com.atlassian.jira.issue.Issue
    import com.atlassian.jira.issue.fields.CustomField
    
    import java.sql.Timestamp
    
    
    return (int) ( System.currentTimeMillis() - getMillsForCstFd("custom field name 1", issue))/(1000*60*60*24)
    
    public long getMillsForCstFd(String _customFiledname, Issue _issue){
        CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName(_customFiledname);
        if(customField == null)
            return 0
    
        Timestamp cstFldDate = (Timestamp) _issue.getCustomFieldValue(customField);
        return (cstFldDate == null) ? 0 : cstFldDate.getTime();
    }
  3. Do reindexation to set values.

In your case "Accepted Date Time" is a custom field.

In this case, a scripted field is a much nicer answer than a post-function plus a custom field.  I just wanted to add that you probably want to set the output to a "number" type, so that you can search it

Hi,

I have executed according to instruction.

>1.Create a scripted field

Issus > Custom Fields > Add Custom Field > Select a Field Type "Scripted Field"

>2.Place a code for scriptRunner to calculate requared value. Somethink like this:

Issus > Custom Fields > Scripted Field  > Configurations > Edit Configuration

>3.Do reindexation to set values.

System > Indexing > (Lock JIRA and rebuild index)Re-Index

But there was nothing changed.

What is the configure of shortage ?

Best Regards,

Pabayos Alaine

Have you added the field to the issue view screen?

When you added the script, did you use the "preview" box at the bottom of the script definition page to test what the output would be?  What did that do?

Sorry.

Your instruction is bellow:

Issus > Custom Fields > Scripted Field  > Configurations > Edit Configuration

is it correct?

 

In the following another way...

Add-On > Script Console> Script

Which is correct?

No, no-one has mentioned the script console because you're working with a scripted field, so the script console is the wrong place to look.

Go to the scripted field, put in the script you want and select an issue to test it with.  What does the preview tell you?

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
Bridget Sauer
Published Thursday in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

348 views 0 6
Read article

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