Dear Community,
I have a field that calculates the difference between two dates:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.util.*
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateResponse = customFieldManager.getCustomFieldObjectByName('Date of First Response');
if(issue.getCustomFieldValue(dateResponse) && issue.created)
{
def dateValue= issue.getCustomFieldValue(dateResponse) as Date
def dateValue2= issue.created
def dif = dateValue.getTime() - dateValue2.getTime()
return dif
}
I want to display value of this field in format: "XX Days YY Hours ZZ Minutes QQ Seconds"
Anyone can help me out?
Thanks in advance.
Hi Patrice,
Instead of collecting and iterating through emails why not iterating through the list of the applications users, where each Application user holds the email address and the display name.
Or even collect in a map the email address (as a key) and the display name (as a value) and the iterate through this map.
Example code
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.user.ApplicationUser
def issue = issue as MutableIssue
def users = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10100")
def userlist = issue.getCustomFieldValue(users) as List <ApplicationUser>
def emailAndNameMap = userlist?.collectEntries {
[(it.emailAddress) : it.displayName]
}
userlist?.each {
log.debug "Email address $it.emailAddress"
log.debug "Display name $it.displayName"
//do some rest calls
}
One last thing why you use the REST api to create the users and not the Java API ?
Hi Thanos,
Many thanks for this and apologies for the delay, was away.
Part of the 'brief' is that I only have a custom field with email addresses separated by semicolons. Users do not exist yet. I have to grab each email, parse first part and use it as DisplayName and create users on a remote Jira instance...
Tried your method to map and .collectEntries as it.emailAddress and it.displayName but it fails as it does not know it is an email address
groovy.lang.MissingPropertyException: No such property: emailAddress for class: java.lang.String
EDIT: I found my original method to be working, I hadn't accounted for trailing white spaces...
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Patrice,
Oh ok, I got the use case wrong (I thought the custom field was a MultiUserPicker).
Glad that you sorted this out.
Regards, Thanos
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.