Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How do i set a default user when using clone post function

Daniel Wellington July 20, 2018

I have used the clone functionality to clone a JIRA if a certain condition is met, however how do I set that a custom user select field is defaulted to a particular user only for the cloned JIRA.

Below is the current syntax

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager

def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// set Scrap field to Yes
def scrapCf = customFieldManager.getCustomFieldObjectByName("POD")
def fieldConfig = scrapCf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Transaction", null)
issue.setCustomFieldValue(scrapCf, option)

checkAttachment = {attachment -> false};
issue.assigneeId = null;
issue.summary = "[Reporting]-"+ transientVars["issue"].summary;
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
UserMessageUtil.success('Backreporting Ticket created.')

 

When i add, the below to it, it doesn't work:

def validatingUser = getFieldByName("Ticket Owner")
validatingUser.setFormValue("stanme")

 

Can anyone help?

1 answer

0 votes
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2018

Hello,

Your last lines are from the Behaviour functionality of ScriptRunner. You can not use it in post functions.

def ticketOwnerCf = customFieldManager.getCustomFieldObjectByName("Ticket Owner")

def stanNameCf = customFieldManager.getCustomFieldObjectByName("stanme")

issue.setCustomFieldValue(stanNameCf, issue.getCustomFieldValue(ticketOwnerCf))
Daniel Wellington July 20, 2018

Hi,

I replacing the last lines with your suggestion, however whilst the cloning still works, the field 'Ticket owner' was not defaulted to 'stanme'; it retained the original value

Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2018

def ticketOwnerCf = customFieldManager.getCustomFieldObjectByName("Ticket Owner")

def stanNameCf = customFieldManager.getCustomFieldObjectByName("stanme")
issue.setCustomFieldValue(stanNameCf, issue.getCustomFieldValue(ticketOwnerCf))
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

and add import:

import com.atlassian.jira.event.type.EventDispatchOption

Daniel Wellington July 20, 2018

Sorry this is very strange - unless I'm missing something this should work:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.customfields.manager.OptionsManager
import com.atlassian.jira.event.type.EventDispatchOption

def optionsManager = ComponentAccessor.getComponent(OptionsManager)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

// set Scrap field to Yes
def scrapCf = customFieldManager.getCustomFieldObjectByName("POD")
def fieldConfig = scrapCf.getRelevantConfig(issue)
def option = optionsManager.getOptions(fieldConfig).getOptionForValue("Transaction", null)
issue.setCustomFieldValue(scrapCf, option)

def ticketOwnerCf = customFieldManager.getCustomFieldObjectByName("Ticket Owner")
def stanNameCf = customFieldManager.getCustomFieldObjectByName("stanme")
issue.setCustomFieldValue(stanNameCf, issue.getCustomFieldValue(ticketOwnerCf))
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

checkAttachment = {attachment -> false};
issue.assigneeId = null;
issue.summary = "[Reporting]-"+ transientVars["issue"].summary;
import com.onresolve.scriptrunner.runner.util.UserMessageUtil
UserMessageUtil.success('Backreporting Ticket created.')

Suggest an answer

Log in or Sign up to answer