It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

set field based on part of another field

Using JIRA Service Desk, customers are set with their email address as their user ID.  Based on the domain in their email I need to set a custom field (client)

I have Script runner and think that will do what I need but not sure where to start.

Any help would be appreciated.


1 answer

1 accepted

Hi Jenifer,

You can build a custom script and add it to the Create transition of the workflow used in that Service Desk. That post function should be called right after the issue is created.

I believe the following code will do more or less what you need:

import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.IssueService
import com.atlassian.jira.bc.issue.IssueService.UpdateValidationResult
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.IssueInputParameters

def Issue issue = issue

// retrieve user
def currentUser = ComponentManager.getInstance().jiraAuthenticationContext?.user

// update issue
if (currentUser?.emailAddress) {
    def IssueService issueService = ComponentAccessor.issueService
    def User adminUser = ComponentAccessor.userUtil.getUser("admin")
    def mailDomain = currentUser.emailAddress.substring(currentUser.emailAddress.indexOf("@")+1)

    IssueInputParameters issueInputParameters = issueService.newIssueInputParameters();
    issueInputParameters.addCustomFieldValue(10704, mailDomain)

    UpdateValidationResult validationResult = issueService.validateUpdate(adminUser,, issueInputParameters)
    if (validationResult.valid) {
        issueService.update(adminUser, validationResult)
    } else {

Thank you so much! It worked perfectly!

I tested this on a regular test project and worked perfect. Added the custom field and the script to the Service Desk project and it is not working. Same user in both instances. I am assuming it has something to do with Service Desk seeing the user as a customer??? Any thoughts? Thank you again I really appreciate it! Jenifer

Yeah, it could definitely be related to the way users are handled in Service Desk. It might be worth to change def currentUser = ComponentManager.getInstance().jiraAuthenticationContext?.user into def currentUser = ComponentAccessor.jiraAuthenticationContext?.user as the first call is actually deprecated. If that does not help, I would suggest to add some logging information around the retrieval of the user.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira Service Desk

How has Jira Service Desk increased productivity in your org?

Hi Jira Service Desk community, Atlassian is on a mission to unleash the potential of all teams, and we know that tools are just one piece of that puzzle. With Jira Service Desk, we have productiv...

219 views 0 3
Join discussion

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you