Hello
I want to get a value of customfield using by groovy script..
And then, I want to set a prefix on issue summary using by customfield value..
it is an example below;
Then first of all... I want to get the value what is 'apple' by groovy script.
and next i want to set a summary..
Actually I know setting a summary by groovy like below
import com.atlassian.jira.issue.Issue
issue.setSummary("Test Summary");
Then it will be set a "Test Summary" as a new issue summary..
However what I want to do is "issue.setSummary(customfieldvalue + summay)"
So...How can I get a customfield value (single select list field type) and how can set a summary..?
Additionally.. I will set it by post-function..
Please let me know.. thanks..
Can this help?
def issueManager = ComponentAccessor.getIssueManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def cField = customFieldManager.getCustomFieldObject("customfield_id") def cFieldValue = issue.getCustomFieldValue(cField) issue.setSummary(cFieldValue + " " + issue.summary);
Last line should probably be:
issue.setSummary(cFieldValue + " " + issue.summary)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My bad, copy paste
I changed the code accordingly
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried below;
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.Issue; def issueManager = ComponentAccessor.getIssueManager() def customFieldManager = ComponentAccessor.getCustomFieldManager() def cField = customFieldManager.getCustomFieldObject("10304") def cFieldValue = issue.getCustomFieldValue(cField) issue.setSummary(cFieldValue + " " + issue.summary);
However it was not working..
I think they have some problem but I don't know why..
def cField = customFieldManager.getCustomFieldObject("10304") def cFieldValue = issue.getCustomFieldValue(cField)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
ahhh.....
it was it..
def cField = customFieldManager.getCustomFieldObject("customfield_10304")
However what I told about customfield type was "Selecet List" type..
It works from "Text Field" but I think it doesn't work from "Select List" Type..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I solve it..
Thanks to Tuncay Senturk and Jamie Echlin..
Also if you don't mind, can you recommend some of sites to learn groovy script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
By following the previous example to get customer field (single line text) value. But still fails!
Could you please let me know? Many thanks!
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def firstnameTypeCF = customFieldManager.getCustomFieldObject("First Name")
def firstnameFieldV = issue.getCustomFieldValue(firstnameTypeCF)
def lastnameTypeCF = customFieldManager.getCustomFieldObject("Last Name")
def lastnameFieldV = issue.getCustomFieldValue(lastnameTypeCF)
issue.setSummary(summary + " - " + firstnameFieldV + " " + lastnameFieldV)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2016-07-21 10:39:21,458 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2016-07-21 10:39:21,458 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TPSHR-1038, actionId: 1, file: <inline script> java.lang.NullPointerException at com.atlassian.jira.issue.IssueImpl.getCustomFieldValue(IssueImpl.java:896) at com.atlassian.jira.issue.Issue$getCustomFieldValue$3.call(Unknown Source) at Script104.run(Script104.groovy:72)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ann,
The
ComponentAccessor.getCustomFieldManager().getCustomFieldObject("First Name")
get as a param the String representation of the custom field's id, should be something like, customfield_12345
So either you have to pass as a param the id or if you want to use the name try
// be aware if you have more than one custom fields with the same name ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Name of the custom field")
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @[deleted]
How did you solve the Single Select List Custom field issue that you were having above?
As you mentioned i could able to extract out Text Field Value but not Single Select List field value. How did you got the value for that field, could you please post here.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You can use below line.
((LazyLoadedOption)cFieldValu).getValue()
here is the import line
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Tuncay Senturk, i am very bad at coding, i am using it like below, but it is throwing an error, please correct me
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.option.LazyLoadedOption;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_12512")
def cFieldValue = ((LazyLoadedOption)cField).getValue()
if (cFieldValue == "Stream Creation")
{
issue.summary = "Stream request has been Submitted"
}
Regards,
Naveen
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
def cFieldValue = issue.getCustomFieldValue(cField)
def selectedValue = ((LazyLoadedOption)cFieldValue).getValue()
if (selectedValue.equals("Stream Creation")) {
// do anything here
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
That did the trick, thanks a lot for all the help, greatly appreciated !!!
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.
By the way, do not forget to check nulls.
def cFieldValue = issue.getCustomFieldValue(cField)
if (null == cFieldValue) return;
def selectedValue = ((LazyLoadedOption)cFieldValue).getValue()
// and also hard coded string should be put before the equality, as below
if ("Stream Creation".equals(selectedValue)) {
// do anything here
}
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Using code i am getting error
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
def issueManager = ComponentAccessor.getIssueManager()
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("10304")
def cFieldValue = issue.getCustomFieldValue(cField)
issue.setSummary(cFieldValue + " " + issue.summary);
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
or
def cField = customFieldManager.getCustomFieldObject(10304L)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, I imported all required libraries at the very beginning of this script:
import com.atlassian.jira.component.ComponentAccessor; import com.atlassian.jira.ComponentManager; import com.atlassian.jira.issue.CustomFieldManager; import com.atlassian.jira.issue.fields.CustomField; import com.atlassian.jira.issue.IssueManager; import com.atlassian.jira.issue.Issue; |
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.