Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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

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


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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Core

How to manage many similar workflows?

I have multiple projects that use variations of the same base workflow. The variations depend on the requirements of the project or issue type. The variations mostly come in the form of new statuses ...

3,971 views 11 5
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you