How can i implement CannedScript interface and have all the necessary files resolved in eclipse

I need to change my existing script to support the CannedScript interface. I could not find any jar files to support this . Can anyone please tel me the location of this to download the jar files. Right now when i try in eclipse i get cannot resolve error.i have gone through many atlassian answers bu t i m still not clear. Step by step instructions would be helpful

2 answers

1 accepted

The jar file you need is script-runner.jar, which is what you can download from marketplace. If you have that on the classpath in your IDE it should work fine.

Awesome. Thank you Jamie

There's 2 more question to this. I have seen some of your existing scripts for eg 'Transition parent to resolve when all subtasks are resolved" . I have understood the script. But when i click that script i get some options to choose the transition state - dropdown & also to choose the resolution. How can this be achieved if i am suppose to write a script . I mean i need to get these options. Now i have written the script in the eclipse IDE and i choose "Script PostFunction' option and provide the link to the script in the file system. In order to get the options to cofnigure the states what am i supposed to do?

2nd-i have 5.2 version of jira so i have installed the groovyrunner 2.1.15 version. But when i try coding in eclipse i get to see some namespaces arent getting resolved.

import com.onresolve.jira.groovy.canned.utils.CannedScriptUtils

import com.onresolve.jira.groovy.canned.utils.ConditionUtils

import com.onresolve.jira.groovy.canned.utils.WorkflowUtils

I have added the jar successfully and i can see some other namespace related to cannedscript. How am i supposed to resolve this?

1. That's just the getParams method.

2. You'll probably find that they are not compiled to class files. Add the jar as ources as well as classes. I don't know how to do this in eclipse, I know nothing about eclipse.

Regarding 1. you mean to say that if we have listed our params in the List getparams we should be able to get the options is it? But i am still not getting. To test it i have copied the same script "Transition parent to resolve when subtask resolve" and i have saved this script and placed in a path. I have then selected "script post-function" and then i have chosen custom script option. I have given this path. i have then published the workflow. but i am still not getting options from where i can select which resolution or workflow action i can choose the way you have written it.. I mean i dnt get this configurable Parent action and Resolution list as shown below. How can i do this? i also got this error when i tried resolving a subtask

/secure/CommentAssignIssue.jspa [scriptrunner.jira.workflow.ScriptWorkflowFunction] Script function failed on issue: PROJ-30, actionId: 5, file: D:\MyGadget\target\jira\home\scripts\state.groovy

groovy.lang.MissingMethodException: No signature of method: com.state.main() is applicable for argument types: ([Ljava.lang.String;) values: [[]]

I think you are not actually implementing CannedScript. If you do that, it will show up with the other canned scripts.

If you just want to run a file, don't implement CannedScript.

Why don't you post your whole code.

Actually as i mentioned before i have used your code only Jamie. I just wanted to see how does the cannedscript works.

I can tell you what i did. I am bit new to this scripting please bare with me .Here are the steps:

1) i have created a groovy file in eclipse

2) i have then copied your groovy code of "Transition parent to resolve when all subtasks are resolved" into the file.

3) I have then added this in post function "Script Post Function - Custom Script"

Its the same code. I can still post it again.

Unfortunately i cudnt copy paste the same code here since it says the script lines is more to fit in this place.

I have the starting lines of the code here..

class State implements CannedScript
	Category log = Category.getInstance(Sbi_Pbi_State.class)
	def projectManager = ComponentAccessor.getProjectManager()
	public final static String FIELD_RESOLUTION_ID = "FIELD_RESOLUTION_ID"
	public String getName()
		return "SBI PBI Active Transition"

	public String getDescription()
		return "when any of the SBI's is moved to active state, PBI is moved to planned state provided the last state is active"
	public List getCategories()
		return ["Function"]

Hi Jamie, can you please mention the steps of how can we implement this cannedscript.

OK, so that all looks fine. Now do you see the script when you view the script workflow functions?

i am sorry Jamie. Where is this script workflow functions?

Sorry, I don;t have time to go through this at this level of details. If I can a moment I will write a tutorial on how to write your own canned scripts.

ok Jamie please let me know abt it

Hi Jamie. I could write my custom canned scripts. This is what i did to get script runner running in JIRA instance.

I had actually 6.0 version of jira so the place where i had to deploy my scripts was wrong which didnt load the scripts.

For those who are using jira 5.2 version drop your canned scripts in

- if groovyrunner 2.1.5 version is used

C:\Program Files\Atlassian\JIRA\atlassian-jira\WEB-INF\classes\com\onresolve\jira\groovy\canned\workflow\postfunctions

and for 6.0 version - if groovyrunner 3.0 version is used

C:\Program Files\Atlassian\JIRA\atlassian-jira\WEB-INF\classes\com\onresolve\scriptrunner\canned\jira\workflow\postfunctions

Install the jar in the JIRA and you can see script console where in one can try out their code. In case we use eclipse IDE for coding install the jar so that you can use the inbuilt methods and also the script can implement the canned script.

Once everything is working fine we can deploy this as a postfunction or listener. To check your canned script try adding a postfunction "Script postfunction" and see if the canned script written by you is appearing in the list. If not check the log for errors.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Nov 29, 2018 in Marketplace Apps

How to set up an incident workflow from the VP of Engineering at Sentry

Hey Atlassian community, I help lead engineering at Sentry, an open-source error-tracking and monitoring tool that integrates with Jira. We started using Jira Software Cloud internally last year, a...

1,709 views 3 11
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you