How to set a date customfield or choice list custom field with the IssueInputParameters ?

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.

9 answers

1 accepted

This widget could not be displayed.

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.

Henning Tietgens Community Champion Apr 23, 2013

You should try the format which is displayed in JIRA while you edit a date field.

It works, thank you Henning and Jamie ;)

SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy") (for me)

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.

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.

This widget could not be displayed.
Henning Tietgens Community Champion Apr 23, 2013

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

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")
}

This widget could not be displayed.

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 ...


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.

This widget could not be displayed.
DateTimeFormatter formater = this.dateTimeFormatterFactory.formatter().forUser(user);
Date dueDate = new Date();
String dueDateFormated = formater.format(dueDate); issueImput.Parameters.setDueDate(dueDateFormated);

This widget could not be displayed.

When I get the date customfield value, it returns this format : "2013-04-24 00:00:00.0"

This widget could not be displayed.

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);

This widget could not be displayed.

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...

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());

This widget could not be displayed.

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

This widget could not be displayed.

do not forget to set up 

issueInputParameters.setSkipScreenCheck(true) if target issue edit screen not contains customfield 

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

203 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you