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

set a custom field or DueDate as a specific time of the day

Ankit Patel February 2, 2018

I have a situation where one of my stakeholder is asking to setup the duedate / duetime (a custom field) to setup SLAs. 

 

They want a specific time of the day to be set as a duetime,

Example, for an issue type ABC, the default due time is 12pm on that day.  So any ticket created at 2am and 6am for issuetype ABC will have sla due time as 12pm. 

 

Is this possible on Jira Service Desk, I am using scriptrunner so any feedback would be helpful.

 

Thanks

Ankit

 

 

UPDATE

Since duedate is only a date field, can someone suggest how we can set this as a custom field?

 

1 answer

0 votes
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2018

Dear @Ankit Patel,

to better understand, when (in the life cycle of an issue) you would like to set a specific date?

And you can not make a system field like Due Date to a custom field. Create a new one with a different name.

So long

Thomas

Ankit Patel February 2, 2018

so for example if I have created a ticket today at 2am, then I want to it to set a due-time (custom-field) as 12pm of the same day. how do i do that using scriptrunner? 

 

Thanks Thomas

 

Ankit

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2018

Dear @Ankit Patel,

best you read this article how to change a custom field.

So long

Thomas

Ankit Patel February 2, 2018

Hi Thomas, 

 

I not aware of the code, so I would need some help if you can elaborate on hot can i set this up. From the link you have provided, i see that the script s for a listener, how do i get it so setup a specific time of the day? 

 

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "My CustomField"}
def changeHolder = new DefaultIssueChangeHolder()tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), "myvalue"),changeHolder)

Any help would be much appreciated

Thanks

Ankit

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 2, 2018

Dear @Ankit Patel,

I have coding skills, but I am not familiar with script runner functionality. However I adapted the upper script to your needs:

import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import java.util.Date.*
import java.util.SimpleDateFormat.*
import java.util.GregorianCalendar.*

// create a today date + time with modified to 23:59
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a")
Calendar calendar = new GregorianCalendar()
calendar.set(Calendar.HOUR_OF_DAY, 23)
calendar.set(Calendar.MINUTE, 59)

def issue = event.issue as Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def tgtField = customFieldManager.getCustomFieldObjects(event.issue).find {it.name == "My Own Due Date"}
def changeHolder = new DefaultIssueChangeHolder()tgtField.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(tgtField), sdf.format(calendar.getTime())),changeHolder)

Unfortunately I have not ScriptRunner installed, so I cannot verify the upper scripts' functionality.

If you have bought this Plugin, I recommend to ask the vendors' professional support to assist.

So long

Thomas

Ankit Patel February 5, 2018

@Nic Brough -Adaptavist- @Adaptavist Supp

Can you help provide some insight on this please?

 

Thanks

Ankit

Nic Brough -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.
February 6, 2018

At a glance, I see nothing wrong with Thomas' code.  Where is it failing and what is the error?

Ankit Patel February 7, 2018

@Thomas Deiler @Nic Brough -Adaptavist-

Thank you for the help so far 

I am getting the below error when I try to run this in script runner

The script could not be compiled:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script193.groovy: 10: unable to resolve class SimpleDateFormat @ line 10, column 18. SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a")

^ Script193.groovy: 10: unable to resolve class SimpleDateFormat @ line 10, column 24. SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss a") ^ 2 errors 

 aa.PNG

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 7, 2018

Dear @Ankit Patel,

the groovy compiler cannot find the class java.util.SimpleDateFormat. I do not know the details of your build environment, but I guess that there is for sure some documentation how to import native Java classes.

So long

Thomas

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events