The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to set due date via rest

aas
Contributor
November 26, 2019

Hello everybody. I need to change due date field via REST API but there no any endpoints to set data and time, and I decided to write REST Endpoint via scriptrunner. Here is code 

@BaseScript CustomEndpointDelegate delegate


setDueDate(
httpMethod: "POST", groups: ["jira-users"]
) { MultivaluedMap queryParams ->
log.setLevel(Level.INFO)

def issue = ComponentAccessor.getIssueManager().getIssueByCurrentKey("TEST-767")
def dueDateField = issue.getDueDate()
log.info("Issue Key" + issue.key)
log.info("Old date: " + dueDateField.toString() + " Class: " + dueDateField.getClass().toString())
Timestamp date = new Timestamp(2020, 1, 15, 18, 30, 0, 0)
log.info("Date must be set : " + date)
issue.setDueDate(date)
def newDueDateField = issue.getDueDate()
log.info("New date: " + newDueDateField.toString() + " " + newDueDateField.getClass().toString())
return Response.ok(new JsonBuilder([abc: 42]).toString()).build()
}

When I look at logs everythin is fine and new date is seted

INFO [runner.ScriptRunnerImpl]: Old date: 2019-11-30 18:00:00.0 Class: class java.sql.Timestamp
INFO [runner.ScriptRunnerImpl]: Date must be set : 3920-02-15 18:30:00.0
INFO [runner.ScriptRunnerImpl]: New date: 3920-02-15 18:30:00.0    class java.sql.Timestamp

But when I look into issue the old date is seted there

I try in this script add a comment and it works, but date doesn't change :(

ComponentAccessor.getCommentManager().create(issue, issue.getReporterUser(), "bla bla", false)

Will be glad to any help.

 

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
David_Bakkers
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Champions.
April 5, 2020

There already is a method of setting the due date of an issue, as 'duedate' is a valid field, as per this section of the Jira Server REST API documentation.

The field can be set when the issue is created, or updated afterwards.