HI All,
I have many Rest End points and Behaviours Scripts in JIRA server and now when migrating to JIRA cloud , the script runner for JIRA cloud does not support the below features -
1) REST end points
2) Behaviours
Could you let me know what can be the alternative for that ?
Thanks Clinton. Question How Can i test in Staging environment before It moves to Production.If I remove a line in staging environment I get an error stating
Cannot invoke method getCustomFieldValue() on null object
java.lang.NullPointerException: Cannot invoke method getCustomFieldValue() on null object at Script280.run(Script280.groovy:14)
Code Snippet
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.getCustomFieldObjectByName('Live Date');
def dateFieldObject2= customFieldManager.getCustomFieldObjectByName('Start Date');
Issue issue;
//def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ATP-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)/30
}
I have had some issues in the past where having my script resolve the getCFV() in the compare didn't work correctly as I would've expected. I had to put them into variables first. So my code would do the 'def dateValue...', and then do the 'if....' using those variables. At least then I could put a forced 'return dateValue;', etc. after each 'def....' to make sure I was actually getting access to the data. I have also experienced some headaches with the getCFObyName, getCFO('customfield_xxxxx') worked for me, so didn't bother to look and see why byName wasn't giving me what I wanted.
Wish I had a clearer answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Clinton. So my below code snippet which gives the error in Staging area will work fine ? Currently it throws Exception because of 2 reasons - it needs an EPIC on which getcustomerFieldsByName needs to be called upon
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.getCustomFieldObjectByName('Live Date');
def dateFieldObject2= customFieldManager.getCustomFieldObjectByName('Start Date');
/Issue issue;
//def issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ATP-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)/30
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have fixed all above issues. Thanks a ton Alexey for your quick help
I just need an help to make the above script more generic where ,it can work for any Current Key its working upon
issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISSUEKEY-1")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
issue should be predefined as the issue that is calling the script, so I am pretty sure if you remove:
Issue issue = issue
issue = ComponentAccessor.issueManager.getIssueByCurrentKey("ISSUEKEY-1")
Then it should just pick the issue you are working on.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Alexey. Few Query . When I am in Staging Environment and go to Custom Fields Page, I can see Live Date but not Collections Start date which is in Prod Enviornment.
Please suggest if other part of the code looks fine. Also, my understanding is this script when it goes to production ,it will calculate "Elapsed Duration" - My custom scripted field Automatically as soon as Live date and Collections Start date is added
What changes I should have in my code where it refers to "Current EPIC Key".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You should change
def dateFieldObject= customFieldManager.getCustomFieldObject('Live Date');
def dateFieldObject2= customFieldManager.getCustomFieldObject('Collections Start Date');
to
def dateFieldObject= customFieldManager.getCustomFieldObjectByName('Live Date');
def dateFieldObject2= customFieldManager.getCustomFieldObjectByName('Collections Start Date');
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As far as I understand there is only one question left. How to make the script more generic because right now you have an issue key defined in the script. It would depend on how you want to launch your script. Is it a scripted field , validator, listener or you want to launch it just from Script Console?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.