Hi,
I'm trying to use this sample script to add organization on create but I'm having compiling issues
import com.atlassian.fugue.Option import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.issue.ModifiedValue import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.util.DefaultIssueChangeHolder import com.atlassian.servicedesk.api.ServiceDeskManager import com.atlassian.servicedesk.api.organization.OrganizationService import com.atlassian.servicedesk.api.organization.OrganizationsQuery import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequest import com.atlassian.servicedesk.api.util.paging.LimitedPagedRequestImpl import com.onresolve.scriptrunner.runner.customisers.PluginModule import com.onresolve.scriptrunner.runner.customisers.WithPlugin @WithPlugin("com.atlassian.servicedesk") @PluginModule ServiceDeskManager serviceDeskManager @PluginModule OrganizationService organizationService MutableIssue issue = issue def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() 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 serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer // get the available organizations for that project def organizationsQuery = new OrganizationsQuery() { @Override Option<Integer> serviceDeskId() { return new Option.Some<Integer>(serviceDeskId) } @Override LimitedPagedRequest pagedRequest() { return new LimitedPagedRequestImpl(0, 50, 100) } } // get all the organizations configured for that project def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results // get the Organizations custom field def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Organizations") // finally update the organizations custom field cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), organizationsToAdd), new DefaultIssueChangeHolder())
The compiling issues are related with two lines of code
1. def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer
2. def organizationsToAdd = organizationService.getOrganizations(currentUser, organizationsQuery)?.right()?.get()?.results
Both return the error (No such property id for class: R or No such property results for class: R)
If I try to log serviceDeskProject?.right()?.get() I get the result below:
I want to get the value 3 from serviceDeskId but I'm unable to do it. I did already try
serviceDeskProject?.right()?.get()?.getId as Integer and serviceDeskProject?.right()?.get()?.serviceDeskId as Integer but I still get the same compilation error (No such property id for class: R or No such property results for class: R)
serviceDeskId :Either.Right(ServiceDeskImpl{serviceDeskId=3, projectId=12502, projectName=ITSM TEST, accessConfig=AccessConfig{publicSignUp=false, openAccess=true}, createdByUserKey=some(afr), createdDate=some(2018-03-19 11:32:11.095), createdWithEmptyProject=some(true), createdAtVersion=some(3.11.0-REL-0005), legacyCommentTransitionDisabled=true})
Hi,
I get this when I execute it in a workflow
2018-10-29 10:20:34,222 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2018-10-29 10:20:34,222 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: ITSM-119, actionId: 1, file: <inline script> java.lang.NullPointerException at com.atlassian.servicedesk.internal.feature.organization.api.OrganizationServiceImpl.getOrganizations(OrganizationServiceImpl.java:156) at com.atlassian.servicedesk.api.organization.OrganizationService$getOrganizations$0.call(Unknown Source) at Script22.run(Script22.groovy:40)
Im not sure.
I'll try and check again at the upgraded instance I have access
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you for sharing your script and I am running this script on JSD 4.0.2 and Jira 8.0.2 as "Script listner" in create issue event and I am getting following error. I am new to scriptrunner and JIRA and trying to get organizations field from the email address of reporting user using customer portal.
Any help will be really appreciated. Thank you in advance.
2019-05-29 11:56:55,100 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-05-29 11:56:55,100 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TCH-31, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: com.atlassian.servicedesk.internal.feature.servicedesk.ServiceDeskImpl.isLeft() is applicable for argument types: () values: [] Possible solutions: inspect(), inject(groovy.lang.Closure), inject(java.lang.Object, groovy.lang.Closure), sleep(long), sleep(long, groovy.lang.Closure), isCase(java.lang.Object) at Script474.run(Script474.groovy:28)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dhavval Aarya ,
Not sure if there are any changes on the . I'm currently on 7.12.3 and seems to be working fine for me.
Could you try removing that block and see if it runs?
Br
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Gezim Shehu [Communardo]
Thank you for your reply. now I am getting following error.
2019-05-29 11:40:58,021 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-05-29 11:40:58,022 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script457.groovy: 38: unexpected token: Option @ line 38, column 5. Option<Integer> serviceDeskId() { ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Kindly replace with < and > instead of < or >
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello @Gezim Shehu [Communardo] ,
Thank you for your time for helping me on this. I have tried your script on both workflow scriptrunner post function and scriptrunner script listner on create issue event and I am getting error on both places.
is there any way I can directly send you an email and stop spamming this place and once solution is found, I can post it here?
Best Regards,
Dhavval Aarya
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Dhavval Aarya ,
Please try it on the script console and try debugging it on where it fails.
For script console you can use something like this to help retrieve the issue
import com.atlassian.jira.component.ComponentAccessordef issue = ComponentAccessor.getIssueManager().getIssueObject('ABC-123')
While debugging can be done by simply logging, at least seeing until when your script executes.
log.warn('test')
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you @Gezim Shehu [Communardo] for your reply, after enabling log.warn, i am getting following information with the error:
2019-06-06 13:48:43,546 ERROR [runner.AbstractScriptListener]: ************************************************************************************* 2019-06-06 13:48:43,546 ERROR [runner.AbstractScriptListener]: Script function failed on event: com.atlassian.jira.event.issue.IssueEvent, file: <inline script> org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script47.groovy: 51: The return type of com.atlassian.fugue.Option serviceDeskId() in Script47$1 is incompatible with java.util.Optional in com.atlassian.servicedesk.api.organization.OrganizationsQuery . At [51:5] @ line 51, column 5. @Override ^ 1 error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you please share the entire script how you are using it?
My guess there were api changes going from 7.x to 8.x. However I'm still on 7.x so i need to check the script first.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
As you've mentioned above to use your script in post function of workflow at last step of create transition is as below and also the error message.
:
Time (on server): Tue Jun 11 2019 10:12:35 GMT+0200 (Central European Summer Time)
The following log information was produced by this execution. Use statements like:log.info("...") to record logging information.
2019-06-11 10:12:35,178 ERROR [workflow.ScriptWorkflowFunction]: ************************************************************************************* 2019-06-11 10:12:35,186 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: TCH-40, actionId: 1, file: <inline script> groovy.lang.MissingMethodException: No signature of method: com.atlassian.servicedesk.internal.feature.servicedesk.ServiceDeskImpl.isLeft() is applicable for argument types: () values: [] Possible solutions: inspect(), inject(groovy.lang.Closure), inject(java.lang.Object, groovy.lang.Closure), sleep(long), sleep(long, groovy.lang.Closure), use([Ljava.lang.Object;) at Script48.run(Script48.groovy:28)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Below is a script I use to add an organization on create issue/ticket
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.servicedesk.api.ServiceDeskManager
import com.atlassian.servicedesk.api.organization.OrganizationService
import com.atlassian.servicedesk.api.organization.OrganizationsQuery
import com.onresolve.scriptrunner.runner.customisers.PluginModule
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import org.apache.log4j.Level
log.setLevel(Level.INFO)
@WithPlugin("com.atlassian.servicedesk")
@PluginModule
ServiceDeskManager serviceDeskManager
@PluginModule
OrganizationService organizationService
MutableIssue issue = issue
def sdUser = ComponentAccessor.getUserManager().getUserByKey('robotuser')
def serviceDeskProject = serviceDeskManager.getServiceDeskForProject(issue.projectObject)
// if the project is not Service Desk type, return
if (serviceDeskProject.isLeft()) {
log.error "${serviceDeskProject?.left()?.get()}"
return
}
//get SD ID
def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer
//Build Org Query
def organizationsQuery = organizationService.newOrganizationsQueryBuilder().serviceDeskId().build()
// get all the organizations configured for the project
def organizationsToAdd = organizationService.getOrganizations(sdUser, organizationsQuery)?.right()?.get()?.results
def cf = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName('Organizations')
def existing = cf.getValue(issue)
for (organization in organizationsToAdd){
if (organization.toString() == 'Organization Name goes here'){
if(!existing.isEmpty()){
if(!existing.contains(organization)){
existing.add(organization)
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), existing), new DefaultIssueChangeHolder())
log.info("Organization Added!")
}
else if(existing.contains(organization)){
log.info("Organization Already Exists!")
return
}
}
else{
cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf), [organization]), new DefaultIssueChangeHolder())
log.info("Organization Set!")
}
}
}
//x
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
//get SD ID
def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer
It is in this line of code that I get the compiling error No such property id for class: R. Trying your script I get the same error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Did you try running the script in a post function ? I pulled it out of a functional workflow. Should be ok, despite the warnings.
Just put it in the last order
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gezim,
Yes I did run it on a scriptrunner postfunction. Maybe we are running different ServiceDesk API Versions?
I'm running JIRA Service Desk - 3.14.0-REL-0006
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Im on JIRA 7.3.0 and SD 3.3.0.
But I have a dev instance currently upgrading. Let me check there later
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Hugo NoronhaI tried and you are right it didn't work.
However debugging quickly i found that the output of organization.toString() now has changed so i replaced it instead with organization.name
Now it works
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gezim,
And what about
def serviceDeskId = serviceDeskProject?.right()?.get()?.id as Integer
According to what I read, it's only working with Service Desk 3.3.0 API. What were the changes that you made on the above line of code for your script to work?
Thanks in advance :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did not make changes to that.
It worked just by the one line fix :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
:) Ok, I'm reindexing my instance. I'll feedback results as soon as I test your solution
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gezim,
I still get a lot of compilation errors
So it does not compile. Any thoughts?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I also get errors. These however are script runners type error/warning.
In my instance it executes fine.
Have you tested in a workflow?
Br
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.