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.
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, issue.id, issueInputParameters) if (validationResult.valid) { issueService.update(adminUser, validationResult) } else { log.debug(validationResult.errorCollection) } }
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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.