Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

how to add "shared with" users to a service desk issue

I've been trying add shared-with customers to my service desk issue with the following code which seems to work but doesn't seem to add the users to the "Shared with" list on my portal.  What am I missing?

The goal is to add all of the approvers to the shared-list so they can see the ticket details.

Here's the code I'm using in the script runner for now:

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.loader.ActionDescriptor
import com.atlassian.jira.issue.IssueInputParametersImpl
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.atlassian.jira.plugins.share.ShareService
import com.atlassian.jira.plugins.share.ShareBean

def issueManager = ComponentAccessor.getIssueManager()
def workflowManager = ComponentAccessor.getWorkflowManager()
def issueService = ComponentAccessor.getIssueService()
def userManager = ComponentAccessor.getUserManager()

@WithPlugin("com.atlassian.jira.jira-share-plugin")
@PluginModule
ShareService shareService

def issue = issueManager.getIssueByCurrentKey("abcd-36")

Set<String> userkeys = Collections.singleton("flast")
Set<String> emails = Collections.emptySet()
String message = "Welcome to my ticket"

def shareBean = new ShareBean(userkeys, emails, message, null)

def validateResult = shareService.validateShareIssue(autoUser, shareBean, issue)
if (!validateResult.isValid()) {
    log.error "Failed to validate Share Issue parameters:\n${validateResult.errorCollection}"
    return null
}

shareService.shareIssue(validateResult)
log.info(autoUser.displayName + " is sharing " + issue.key + " with " + userkeys)

 Does service desk use a different shared-with mechanism?  Can I control it programmatically?

1 answer

Suggest an answer

Log in or Sign up to answer

Just answered my own question.  In service-desk, the "Shared with" is really the participants when looking at the associated Jira ticket.

The following code worked for me:

//
// add all of the users from 'Approvers' into the 'Request participants' field
//
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.user.ApplicationUser

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def issueManager = ComponentAccessor.getIssueManager()
def userManager = ComponentAccessor.getUserManager()

String AUTO_USER_NAME = "auto_user"
String PARTICIPANT_FIELD_NAME = "Request participants"
String APPROVERS_FIELD_NAME = "Approvers"

def participantsField = customFieldManager.getCustomFieldObjectsByName(PARTICIPANT_FIELD_NAME).iterator().next()
def approversField = customFieldManager.getCustomFieldObjectsByName(APPROVERS_FIELD_NAME).iterator().next()

def participants = (List<ApplicationUser>)issue.getCustomFieldValue(participantsField)
def approvers = (List<ApplicationUser>)issue.getCustomFieldValue(approversField)

def autoUser = userManager.getUserByName(AUTO_USER_NAME)

if (approvers.isEmpty()) {
// nothing to do
return;
}

// we have to create a new list because the current one might be Collections.emptyList()
List<ApplicationUser> users = new ArrayList<>();
users.addAll(participants);
users.addAll(approvers);

issue.setCustomFieldValue(participantsField, users)
if (issueManager.updateIssue(autoUser, issue, EventDispatchOption.ISSUE_UPDATED, false /* no email */)) {
log.info("issue " + issue.id + " updated participants " + users)
} else {
log.info("issue " + issue.id + " could not update participants " + users)
}

 

TAGS
AUG Leaders

Atlassian Community Events