Forums

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

Groovy condition customfield user picker

AccessHolding July 5, 2018

Hi All,

I have a script in place which checks, if a customfield (single-user-picker) is set or not.

...
...

def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ASD: On behalf of")
def newReporter = issue.getCustomFieldValue(customField) as ApplicationUser

if (customField){
    issue.setReporter(newReporter)
} else if (!customField){
    log.info("Reach else tree")
    issue.ReporterId = currentAppUser
}

ComponentAccessor.getIssueManager().updateIssue(issue.getReporter(), issue, EventDispatchOption.ISSUE_UPDATED, false)

The if condition works fine and the reporter will be replaced but unfortunately the else statement will never be executed. Instead of the currentAppUser the ticket creates "Anonymous" as a reporter.

Any suggestions?

Best,

Kristian

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 5, 2018

Hello,

Add logging and have a look what is the value for the customField is if this custom field is not set. You should see logs in the atlassian-jira.log file

def currentAppUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().name

def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("ASD: On behalf of")
def newReporter = issue.getCustomFieldValue(customField) as ApplicationUser

log.error("customField: ${customField.toString()}")
if (customField){
    issue.setReporter(newReporter)
} else if (!customField){
    log.info("Reach else tree")
    issue.ReporterId = currentAppUser
}

ComponentAccessor.getIssueManager().updateIssue(issue.getReporter(), issue, EventDispatchOption.ISSUE_UPDATED, false)

AccessHolding July 5, 2018

Hi Alexey,

I found out thats wrong. 

if (newReporter != null && customField != null) {
...
}

Its fixed and working perfectly.

Thanks anway.

Suggest an answer

Log in or Sign up to answer