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

Alaine_Pabayos January 18, 2016

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 vote
Vasiliy Zverev
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.
January 18, 2016
  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.

Vasiliy Zverev
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.
January 18, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 19, 2016

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

Alaine_Pabayos January 20, 2016

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

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 21, 2016

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?

Alaine_Pabayos January 25, 2016

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?

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 25, 2016

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
TAGS
AUG Leaders

Atlassian Community Events