Hi,
My request is very simple :
I want to set customfield values during a transition by groovy script. I'm able to do this with text customfield, like this :
IssueInputParameters issueInputParameters = new IssueInputParametersImpl(); issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_13700","All Closed"); issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_12704",issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_12704")));
This code works for text customfields, but not for date or choice list customfields.
I heard that for choice list customfields, I have to use the option ID, but I have not tried yet.
Is anyone can help me ?
Thank you.
This code should works but it doesn't :
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); date = sdf.format(issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10203"))) issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_10203",date);
Does anyone know what is the ".0" after "2013-04-24 00:00:00" ? it seems to be milliseconds number, but event with
SimpleDateFormat("yyyy-MM-dd hh:mm:ss.S") or SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS"), it does not work.
You should try the format which is displayed in JIRA while you edit a date field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It works, thank you Henning and Jamie ;)
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") (for me)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
as by this works, I do not recommend it.
As it does not take care of different time zones and therefore will be very creative when storing the date fields.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
date fields don't have a "time" component, so it's not really important. If you're adding 7 days to a date, the timezone is not relevant.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
DateTimeFormatter formater = this.dateTimeFormatterFactory.formatter().forUser(user); Date dueDate = new Date();
String dueDateFormated = formater.format(dueDate); issueImput.Parameters.setDueDate(dueDateFormated);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Lubos,
I get error with your code. Maybe I'm missing an import or a base script declaration?
dateTimeFormatterFactory is declared in a dynamic context, but you tried to access it from a static context.
When I change it to
DateTimeFormatter formatter = ComponentAccessor.getComponent(DateTimeFormatter)
DateTimeFormatter userFormatter = formatter.forUser(user)
Date myDate = new Date()
String dateFormatted = userFormatter.format(myDate)
I get the output format like "Just now" but not the input format for the date picker fields. Please check my answer for use of DateFieldFormat.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henning,
Thank you for your help.
I found for select customfield, with this code :
issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_10205",issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10205")).getOptionId().toString());
For the date issue, I tried to get a date customfield value and to cast it to String, but it didn't work ...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A cast won't work, use a SimpleDateFormat to convert to a string. But you may need to check the default date format that your jira uses. There should be a simpler way, but I don't know what it is.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Jumping into an old thread in case it helps someone in the future. The way I was ultimately able to work around this was by ending my code with:
def update = issueService.validateUpdate(user, issue.id, issueInputParameters)
log.info(update.getErrorCollection().toString())
if (update.isValid()) {
issueService.update(user, update)
}
this returned
INFO : Errors: {customfield_27220=Invalid date format. Please enter the date in the format "dd/MMM/yy h:mm a".} Error Messages: []
So I knew I needed to use SimpleDateFormat("dd/MMM/yy h:mm a") for my date. Hope this helps someone!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For issueInputParameters you need a String representation of the content of the field. So for a select customfield you have to get the value of the option.
issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_12705",issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_12705")).getValue());
For dates I think you have to have a valid String representation of a date for your system, but I'm not sure, I didn't tried that.
Henning
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes... generally it matches what the browser sends. Examples for date and datetimes etc:
inputParameters.with { setOriginalAndRemainingEstimate("4d", "3d") setDueDate "18/Nov/12" setAssigneeId adminUser.name setSummary "updated summary" setProjectId project.id setIssueTypeId issueType.id setReporterId adminUser.name addCustomFieldValue(myNumberField.idAsLong, 3 as String) addCustomFieldValue(firstDate.idAsLong, "3/Jan/2012") addCustomFieldValue(firstDateTime.idAsLong, "30/Jan/13 10:53 PM") }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey,
I know this question is quite old but I found that here is missing a good solution since different Jira instances have different input formats and I worried that my code would break, if this input format will change at some day.
I found the DateFieldFormat class in the API: https://docs.atlassian.com/software/jira/docs/api/8.5.5/com/atlassian/jira/util/DateFieldFormat.html
With this I changed my code to
final DateFieldFormat dateFieldFormat = ComponentAccessor.getComponent(DateFieldFormat)
issueInputParameters.with {
addCustomFieldValue(myDatePickerField.idAsLong, dateFieldFormat.formatDatePicker(myDate))
}
I hope this helps anyone who is looking for a solution for this problem.
Regards
Erik
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do not forget to set up
issueInputParameters.setSkipScreenCheck(true) if target issue edit screen not contains customfield
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for the tip Mladen!
I went a little rogue and added a TBD section on this page. I was hoping it would trigger an atlassian to do something about the information vacuum on this subject. Not a peep so far.
https://developer.atlassian.com/display/JIRADEV/Performing+Issue+Operations
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Has anyone figured out how to set a cascading select field in Jira 6?
I can set the parent option, but I can't figured out how to set both parent and child in one call.
This works to set the parent ...
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637");
I've tried all of the following to set parent/child together, but to no avail:
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637", "10640");
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637, 10640");
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637 10640");
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637-10640");
issueInputParameters.addCustomFieldValue(myField.getIdAsLong(),"10637/10640");
Is this really not documented anywhere?
I am able to get this to work using customField.updateValue together with IssueManager.updateIssue using the code outlined by Eddie Web on this page: https://confluence.atlassian.com/pages/viewpage.action?pageId=163414052
But that seems old school...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is how I managed to do just that (and lost 2 days figuring it out):
issueInputParameters.addCustomFieldValue("customfield_" + fieldId, parentOption.getOptionId().toString()); issueInputParameters.addCustomFieldValue("customfield_" + fieldId + ":1", childOption.getOptionId().toString());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I didn't solve my problem for date custofield.
But I can show how I did for multiple select list ! Here is the code I use :
def varargsMethod(String ... args){ args } potentialImpactOptions = issue.getCustomFieldValue(customFieldManager.getCustomFieldObject("customfield_10905")) Set potentialImpactOptionsID = new HashSet(); if(potentialImpactOptions){ for(Option option : potentialImpactOptions){ temp = option.getOptionId().toString(); potentialImpactOptionsID.add(temp); } } def potentialImpactArray = varargsMethod( potentialImpactOptionsID as String[] ); issueInputParameters = issueInputParameters.addCustomFieldValue("customfield_10905",potentialImpactArray);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
When I get the date customfield value, it returns this format : "2013-04-24 00:00:00.0"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.