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)
```
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
see my similar post
Jira cloud uses REST API call rather than Jave plugin api
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.