Trying to Automatically assign a due date to all created ticket excluding weeks.

Danison Rarama November 9, 2018

Trying to Automatically assign a due date to all created ticket excluding weeks.

I tried this script but giving me an error for the first 3 lines
unable to resolve class com.atlassian.jira.component.componentaccessor

Im using Script runner cloud and just want to make sure all created tickets are automatically set for 5 days not including weekends.

 

```

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp;
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cfTimeline = customFieldManager.getCustomFieldObjectByName("Due Date")
def cfTimelineValue = issue.getCustomFieldValue(cfTimeline).toString()
// Days in the future when the issue is due.
int DueInDays = 5
log.warn ("ASZ Timeline Value: "+ cfTimelineValue )
MutableIssue myIssue = issue;
// Set the number of days.
switch (cfTimelineValue) {
case "1 - Immediately": DueInDays = 1; break;
case "2 - Today": DueInDays = 2; break;
case "3 - Business Week": DueInDays = 5; break;
case "4 - 30 Days": DueInDays = 30; break;
default: DueInDays = 5; break;
}
// Make sure the due date doesn't fall on a weekend.
Date today = new Date();
Calendar MyDueDate = Calendar.getInstance();
MyDueDate.add(Calendar.DATE,DueInDays)
while ([Calendar.SATURDAY, Calendar.SUNDAY].contains(MyDueDate.get(Calendar.DAY_OF_WEEK))) {
MyDueDate.add(Calendar.DATE,1)

 

```

2 answers

0 votes
Kristian Walker _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.
November 13, 2018

Hi Danison,

Thank you for your question.

I can confirm that the reason that your code above is not working in ScriptRunner for Jira Cloud is due to the fact that this code is for ScriptRunner for Jira Server. The reason that this code will not work is due to the fact that Jira Cloud only has a rest API and does not have the same Java API that Jira Server has.

You can see a full list of the differences between the two versions here.

This means that you will need to use the Rest API in order to update the issue and we have an example of how to do update an issue which can be viewed by clicking the Update issue link next to the Examples text below the code box on the Run Script post function.

I have also created an example post function script which you can view here that gets the value of the due date field and increments it by a specified number of weekdays and you can use this example script to achieve your requirements.

In this example script, the date is incremented by the value specified inside of the numberOfWeekdays variable but you could refactor the script to dynamically get this value from a field.


If this response has answered your question can you please mark it as accepted so that other users searching for a similar question can see that this is a correct answer.

Regards,

Kristian

Danison Rarama November 13, 2018

will Give that a try. 

Do you know if there is a script that would execute a Due Date comment?

So if past due date. it will automatically comment into the ticket with 
"Passed due" @assignee @reporter


Kristian Walker _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.
November 13, 2018

Hi Danison,

I can confirm that you would need to create a script that calls the ADD Comment rest API described here in order to create a comment.

I can confirm that we have an example of how to create a comment in the Script Listiner example inside the documentation here.

You will be able to use this example as a reference to create the script you require to add a comment on the issue. 

Regards,

Kristian

0 votes
Tom Lister
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 10, 2018

Suggest an answer

Log in or Sign up to answer