I have tried using:
IssueInputParameters.addCustomFieldValue(customField.getIdAsLong(), issue.getCustomFieldValue(customField).toString())
But this is causing errors in my CreateValidationResult
Community moderators have prevented the ability to post new answers.
This is how I've been doing it, it works well enough for me:
CustomField customField = customFieldManager.getCustomFieldObject(customFieldId); Options options = WebAppsCf.getOptions(null, customField.getRelevantConfig(issue), null); Option newOption = options.getOptionById(newOptionId); ModifiedValue mVal = new ModifiedValue(issue.getCustomFieldValue(customField), newOption ); customField.updateValue(null, issue, mVal, new DefaultIssueChangeHolder());
do I have to use customfield.updateValue? Will a direct implementation of Issue.setCustomFieldValue not work?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By the way I'm guessing that this method will work for setting values of any custom field type that consists of options?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I don't see Issue.setCustomFieldValue in the api's which is probably why i didn't use it But if that method does exist, I think it would work, the important thing is you set the new value as a proper Option object.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kyle I used your method and it worked! Thanks =)))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, select, multi-select, radio and check boxes will work. You might need to tweak it for cascading-select. The same principle will work for other field types too - for dates, use a timestamp, for user fields, a user object, versions for version type fields etc.
However, that code looks like it overrides the current value with a single value. For multi fields, I think you need to pass it a list of options. If you want to update, rather than overwrite, you'll need to fetch the current list and add to it (obviously, for "create", that's irrelevant)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def myCustomField = getCustomFieldObjects(issue).find {
it.name == "My multi-select field"
}
// just passing a values as List/Map.
issue.setCustomFieldValue(myCustomField, [value])
/*
// e. g.
def values = issue.getCustomFieldValue(myCustomField)
values.each
{
Option it ->
...
}
*/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Reading an setting values is documented well in this book linked below.
It also includes very good examples of how to work with Custom Fields of the "Checkboxes" type - which is hard to find documentation for (see page 107-ish).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is my variant of doing this but I'm not really happy yet. This also enables you to set disabled options so beware of this.
// Get the project the issue should be created in. def curPrj = projectManager.getProjectObjByKey("Project I want to set"); // Set the issuetype that should be used. def issueType = issueTypeSchemeManager.getIssueTypesForProject(curPrj).find{it.name=="Issue Type I want to set"}; def issueContext = new IssueContextImpl(curPrj, issueType); def fieldConfig = customfield.getRelevantConfig(issueContext); def options = optionsManager.getOptions(fieldConfig); def optionToSelect = options.find { it.value == "Select Option I want to set" }; return optionToSelect.getOptionId();
Then in issue input parameters remember to treat it as a string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry if this is a very dumb question but how to I declare the optionsManager?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ah i got it:
import com.atlassian.jira.component.ComponentAccessor
def optionsManager = ComponentAccessor.getOptionsManager()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My example of code here
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your code is not related to the select list options!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Niclas, yes but it may help you with an example of modern code that is not from 2013. It also represents Validation technique which is needed if you want your code to be safe.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But there's not a lot of point in giving code that doesn't have anything to do with the question.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
mutableIssueParent.setCustomFieldValue(fieldIssue, value);
FieldLayoutItem fieldLayoutItem = ComponentAccessor.getFieldLayoutManager().getFieldLayout(mutableIssueParent).getFieldLayoutItem(fieldIssue);
DefaultIssueChangeHolder issueChangeHolder = new DefaultIssueChangeHolder();
Map<String, ModifiedValue> modifiedFields = mutableIssueParent.getModifiedFields();
final ModifiedValue modifiedValue = (ModifiedValue) modifiedFields.get(fieldIssue.getId());
fieldIssue.updateValue(fieldLayoutItem, mutableIssueParent, modifiedValue, issueChangeHolder);
// Dont forget this to search the latest elements updated
IssueIndexingService is=ComponentAccessor.getComponent(IssueIndexingService.class);
try {
is.reIndex(issue);
} catch (IndexException e) {
log.error("Erreur reIndexIssue ",e);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Well, it would - you seem to be using strings, when select list fields expect "option" objects.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Unfortunately the only options I have when using the addCustomFieldValue function is (Long , String) or (String, String) , I dont have a choice of (Long, Option). Is there some other way I can get these custom fields populated in my IssueInputParameters variable?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If not what's the correct way to populate these fields after the issue has been created? I've tried using
IssueResult.getIssue().setCustomFieldValue(customField, Option ) but I dont know what to put to get the correct option for the field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.