Hi
I have an EPIC with 2 dates 1) Start Date 2) Live date. I need to find out difference between 2 dates.
I understand scriptRunner Plugin Helps in creating custom Fields for this purpose
Steps Taken -
1. Custom Field create and added to screen
2. Inline script for calculation as below
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('Live Date');
def dateFieldObject2= customFieldManager.getCustomFieldObject('Collections Start Date');
Issue issue = issue
issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISSUEKEY-1")
if(issue.getCustomFieldValue(dateFieldObject) ==null || issue.getCustomFieldValue
(dateFieldObject2)==null)
return null;
else
{
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
return dateValue - dateValue2
}
Current Error :
Cannot invoke method getCustomFieldValue() on null object
java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object
at Script160.run(Script160.groovy:14)
Query :
1. I understand above Error is because its not able to find out Live date and Start date are from EPIC from JIRA which is in Production Environment
2. if I have to Test this I need to Create above fields but I am unable to create EPIC in staging environment
Create Issue - UPG Toolchain Jira Staging #3
"Component/s" field is required and the project "Aditya Test Project" does not have any components.
I referred below useful link
http://igorpopov.io/2014/11/24/rocking-with-jira-script-runner/
3. How Can i Script where it can work for any 2 dates or as the name suggest its custom field calculating difference between 2 dates
4. Kindly suggest if the above code looks fine