Description:
My client is using a issue picker to select an issue in his ticket.
When the issue is picked I try to populate other field base on the information available is the issue he picked.
I want to send the information from the issue he picked to the issue where he picked it.
For exemple he picked an issue who have multiple field. I want to copy the value from one of those field to a field in the ticket he's currently using.
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.MutableIssue;
import com.atlassian.jira.component.ComponentAccessor;
CustomFieldManager customFieldManager = ComponentManager.getInstance().getCustomFieldManager()
def issuePicked = customFieldManager.getCustomFieldObjectByName("Courtier")
def cf = cfValues[issuePicked]
def issueManager = ComponentAccessor.getIssueManager()
def targetIssue = issueManager.getIssueObject(cf)
CustomField acConseiller = customFieldManager.getCustomFieldObjectByName('Conseiller')
CustomField acBureauVentes = customFieldManager.getCustomFieldObjectByName('Bureau de ventes')
CustomField acPodium = customFieldManager.getCustomFieldObjectByName('Podium')
def acConseiller_value = targetIssue.getCustomFieldValue(acConseiller)
def acBureauVentes_value = targetIssue.getCustomFieldValue(acBureauVentes)
def acPodium_value = targetIssue.getCustomFieldValue(acPodium)
issue.setCustomFieldValue(acConseiller,acConseiller_value)
issue.setCustomFieldValue(acBureauVentes,acBureauVentes_value)
issue.setCustomFieldValue(acPodium,acPodium_value)
I would advise to use another method to update a custom field value, i.e. :
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
CustomField acConseiller = customFieldManager.getCustomFieldObjectByName('Conseiller')
def acConseiller_value = targetIssue.getCustomFieldValue(acConseiller)
def acConseiller_current_value = issue.getCustomFieldValue(acConseiller)
acConseiller.updateValue(null, issue, new ModifiedValue(acConseiller_current_value, acConseiller_value), new DefaultIssueChangeHolder())
Also to get the custom field using its ID (so the script will still be working if an admin changes the field name) :
int acConseillerId = 12345
CustomField acConseiller = customFieldManager.getCustomFieldObject(acConseillerId)
Antoine
Hi Antoine,
I will change the method right away
Thank you so much for the quick answer.
The problem is the value is in another issue. An issue select by the client in an custom field issue picker.
I'm not sur how to resolve this
for exemple conseiller is a field in the ticket cac-254
the client select cac-254 in another issue for exemple act-293
I need the field to be updated in the issue act-293 using the value from the issue cac-254
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I see. Is the field a "Single Issue Picker" custom field ?
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.
Then it should be pretty straight forward, since the value you get from retrieving that custom field value is an "Issue" :
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.issue.ModifiedValue
int issuePickerId = 12345
CustomField issuePicker = customFieldManager.getCustomFieldObject(issuePickerId)
def targetIssue = issue.getCustomFieldValue(issuePicker)
int acConseillerId = 11111
CustomField acConseiller = customFieldManager.getCustomFieldObject(acConseillerId)
def acConseiller_current_value = issue.getCustomFieldValue(acConseiller)
def acConseiller_value = targetIssue.getCustomFieldValue(acConseiller)
acConseiller.updateValue(null, issue, new ModifiedValue(acConseiller_current_value, acConseiller_value), new DefaultIssueChangeHolder())
Just update the IDs with your custom field IDs.
What it does :
Hope this is what you are aiming for.
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.
I'm sorry to ask for your help once more but since once of the field is an user picker I'm not able to get the value ''name'' in the costumfield
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You can use these methods :
int userPickerId = 10800
def cfUserPicker = customFieldManager.getCustomFieldObject(userPickerId)
def cfUserPickerValue = issue.getCustomFieldValue(cfUserPicker)
def userName = cfUserPickerValue.getDisplayName()
def userKey = cfUserPickerValue.getName()
Check the javadoc to see what methods are available for a user object :
https://docs.atlassian.com/software/jira/docs/api/7.1.0/com/atlassian/jira/user/ApplicationUser.html
Antoine
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.