Hi,
I try to get single list custom field value through Script Runner.
I found some posts which say that this can be done through Options object.
When I try to do this I get this error message:
unable to resolve class Options
Version:
JIRA v7.0.3
JIRA Service Desk v3.0.3
Thanks for your help
Pierre
My code is the following:
import com.atlassian.jira.ComponentManager import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.CustomFieldManager import com.atlassian.jira.issue.fields.CustomField import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.Issue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.user.util.UserUtil import com.atlassian.crowd.embedded.api.Group import com.atlassian.jira.issue.customfields.manager.OptionsManager MutableIssue issue = issue CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager(); // Mise à jour du champ TEST_MAJ_SCRIPT_RUNNER champ texte simple issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName("TEST_MAJ_SCRIPT_RUNNER"), "TOTO"); custom_field = customFieldManager.getCustomFieldObjectByName("TECHNOLOGIE"); cfConfig = custom_field.getRelevantConfig(issue); value = ComponentAccessor.optionsManager.getOptions(cfConfig)?.find { it.toString() == 'Test'} issue.setCustomFieldValue(customFieldManager.getCustomFieldObjectByName("TECHNOLOGIE"), value); Options fieldVal =(Options) issue.getCustomFieldValue(custom_field)
Pierre,
You get this error because you have not import the Options. But as you can see in the groovy script Kristian provided, you can avoid this kind of compilation errors by using def to declare variables. For your question "how you can write variable value in JIRA Log files " you can just
log.debug("Issue Key is ${issue.key}")
and enable script runner debugging (Profiling and Logging -> configure new package with package name 'com.onresolve' and set logging lvl to DEBUG). In order to see you log messages you can use the built in script - view server log files.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
It does not work. Is there a way I can write my variable value in JIRA Log files?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Script variables are stored in memory when the script is run for the lifetime of the script. You cannot write out to the log file. If you know the value you are searching for then you create a seperate variable with this value in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I finally did something like
custom_field = customFieldManager.getCustomFieldObjectByName("TECHNOLOGIE"); fieldval = issue.getCustomFieldValue(custom_field);
and I get my result.
Thanks a lot for your help Kristian
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks for your help Krisitian.
I have no problem to set the value of my field, which I made with a code like yours.
Now, I want to be able to get the value to use it later in my code.
Pierre
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In my example code below the value variable has the option value stored and can be used again later in on in the script. If you get the option values how I have below the they will be stored in variables that can be used later.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Pierre,
I have enclosed some code below which shows how to set an option for a Multi Select field that was wrote on JIRA 6.4.12 and Script Runner 4.1.3.
The code gets the Client select list field and finds the XX option in it before applying it to the issue. The post function for this code should always be place first in the list of post functions to ensure the field is set before the issue is updated and indexed.
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.MutableIssue // Get a pointer to the issue MutableIssue issue = issue // Get the Custom Field Manager def customFieldManager = ComponentAccessor.getCustomFieldManager(); //Get the custcom Field def custom_field = customFieldManager.getCustomFieldObjectByName("Client"); // Get the Config for the field def fieldConfig = custom_field.getRelevantConfig(issue) // Find the option to set def value = ComponentAccessor.optionsManager.getOptions(fieldConfig)?.find { it.toString() == 'XX'} // Set the value of the field issue.setCustomFieldValue(custom_field, value)
I hope this helps.
Kristian
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.