Hello Team,
I have a requirement to copy the value from a dropdown custom field to a number custom field, when issue is edited.
Could anyone please help me with the scriptrunner listener script for doing this task.
Thanks,
Akhil
There are no listeners that directly do what you want if I recall correctly.
Instead, do the following:
# Create an issue updated event Listener.
# In the script section, add a script that pulls the value of your drop down custom field.
# Parse this variable to an update field value to update your number field.
These are the steps needed.
Look up how to get values from a select list and update an issue in the official documentation from Scriptrunner.
Hello Ismael,
Thanks for your response. I have made up a groovy script as shown below:
But I am not able to fetch the values from drop down custom field and assign it to number field.
Any help is highly appreciated.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.event.type.EventDispatchOptionimport com.atlassian.jira.issue.CustomFieldManagerimport com.atlassian.jira.issue.UpdateIssueRequestimport com.atlassian.jira.issue.search.SearchProviderimport com.atlassian.jira.jql.parser.JqlQueryParserimport com.atlassian.jira.security.JiraAuthenticationContextimport com.atlassian.jira.web.bean.PagerFilterimport com.atlassian.jira.issue.MutableIssue
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)def searchProvider = ComponentAccessor.getComponent(SearchProvider)def issueManager = ComponentAccessor.getIssueManager()import com.atlassian.jira.issue.Issue
def customFieldManager = ComponentAccessor.getCustomFieldManager()def SP_1 = customFieldManager.getCustomFieldObject("14318")def SP_2 = customFieldManager.getCustomFieldObject("10002")
def issue = event.issue as IssueMutableIssue issueToUpdate = (MutableIssue) issue;issueToUpdate.setCustomFieldValue(SP_2, SP_1);
Is there anyone who can help me with this script listener part.
No what you have done above would likely not work.
You need the value from the field not the field and what you are doing is just getting custom field object. I do not see you pulling the value itself out.
def SP_1 = customFieldManager.getCustomFieldObject("14318") //Not sure why you are getting this I assume you are attempting to get the customfield itselfdef SP_2 = issue.getCustomFieldValue("10002")?.value //Assuming this is your drop down
As for parsing the value, what is issueToUpdate?
If it is the same issue then you should be parsing it in the form of
issue.setCustomFieldValue(SP1, SP2)issueManager.updateIssue(user, issue, EventDispatchOpton.ISSUE_UPDATED,false)
This is a sample of what you really need to do.
Recommend looking at samples at the Scriptrunner page itself
Hi Ismael,/ Experts here in Community
may be you can help me here. We want in Our sevice Desk Projects Issue Security that only Creator/ Request Participant and group of SD Agents should see the Ticket and not all.
As of now with Jira its not possible for Request Participant. I have created a Script Listner which would copy the Request Participant to one Custom Field and this Custom Field can be used in Issue Security page.
As of now its in Test Project and test is successful. I have assigned thr Script Listner to "Issue Update" event because a event such as "Request Participant changed" is not in Jira. My worry is :: Will it have the performance Problems because it will be triggerd with every Issue Update ?
Thanks in Advance.
PreetiD
Yes it will.
Each time the issue in question is updated, it would repopulate it with the values because the script runs.
Instead of this, I would do a check of the values from both fields(request participant vs your custom field) first and exit the script if the values match.
Remember to restrict the event to your project to avoid it triggering for all projects.
A better solution would be add the script to your workflow where by when the status changes, the list of participants is repopulated.
This should be less system intensive than triggering an event from my experience.
It looks like you're new here. Sign in or register to get started.