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

Next challenges

Recent achievements

Recognition

  • Give kudos
  • My kudos

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Only add specific organizations when creating a ticket

Hi all together,

we are using Scriptrunner in our JIRA / JSD environment.

I implemented the functionality from this post: https://community.atlassian.com/t5/Jira-questions/auto-add-organization-on-creation-of-ticket/qaq-p/25440 It works perfectly fine.

I would now like to modify it a little bit. The idea is to only add two specific Organizations whenever a ticket is created. I am totally new to groovy and also my knowledge of Java is just little.

My idea is to loop the variable "organizationsToAdd" and if the value is like my needed organization the script should add it to the customfield.

Something like this:

for (int i = 0; i< organizationstoadd.length; i++){ 
    if (organizationsToAdd[i].name == "org1" || organizationsToAdd[i].name == "org2" )continue
    else delete organizationsToAdd[i]
}

My problem is now that I don't know what "organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results" returns and how I can access it. Is it an array or a list?

Can you perhaps give me hint how I can find out what is returned by methods and stuff like this in general?

I tried log.debug() but it is not writing anything in log console of Scriptrunner.

 

I would be really really happy if you can help me a little bit

Many thanks and best regards

Hannah

2 answers

1 accepted

1 vote
Answer accepted

Ok Hannah, 

Try the following in a script listener 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.CustomerOrganization
import com.atlassian.servicedesk.api.organization.OrganizationService

def serviceDeskManager = ComponentAccessor.getOSGiComponentInstanceOfType(ServiceDeskManager)
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(issue.projectObject)

// if the project is not a Service Desk one then do nothing
if (serviceDeskProject.isLeft()) {
log.error "${serviceDeskProject?.left()?.get()}"
return
}

def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations")
def organizationsToAdd = getOrganizations("Organization B", "Organization C")

cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), organizationsToAdd), new DefaultIssueChangeHolder())


List<CustomerOrganization> getOrganizations(String... organizationNames) {
def adminUser = ComponentAccessor.getJiraAuthenticationContext().loggedInUser

def organisationService = ComponentAccessor.getOSGiComponentInstanceOfType(OrganizationService)
def organizationQuery = organisationService.newOrganizationsQueryBuilder().build()
def organization = organisationService.getOrganizations(adminUser, organizationQuery)

if (organization.isLeft()) {
log.warn "${organization?.left()?.get()}"
return null
}

organization.right().get().results.findAll { it.name in organizationNames }
}

You may get some errors in the UI but are because of the static type checking, so you can safely ignore them. If you think that the script does not work as expected, check the application logs.

Please let me know how this went.

Regards, Thanos

Many many thanks Thanos! It is working as expected!

That's great.

Sorry for the delayed response, but we were a bit busy with developing this period. 

Regards, Thanos

@Thanos Batagiannis _Adaptavist_ 

Hi Thanos,

I have my very own Endgame fast approaching!

Similar to Hannah, When a ticket is created via the customer portal, we need all the Organizations the (Reporter) has been associated with auto-assigned to the issue. 

I have found/implemented the script on your website, however it returns ALL Orgs linked to the project regardless of the (current reporters) association

I would like to edit the script if possible, but as a total novice to scripting I don't no were to start or the correct syntax? 

https://scriptrunner.adaptavist.com/5.4.47/jira/recipes/workflow/servicedesk/email-linked-issue-watchers.html#_3_add_the_script

   

We are running JIRA v7.12.3 and JSD 3.8.1

 

Thanks Paul 

Hey,

is there nobody who can help me with this? :-/

Thanks and BR
Hannah

Hy Hannah,

Which service desk version you use ?

Hi Thanos,

we use JSD 3.8.1 with JIRA 7.5

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence Cloud

Share your Confluence Cloud experience for a chance to win $500!

Take our 5-minute survey to win a $500 Visa gift card! Are you currently using Confluence Cloud? We want to hear from you! Fill out this quick survey about your Confluence Cloud experience so we ...

292 views 5 14
Read article

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