Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Figure out what scripts are doing

Dani Miles
Contributor
January 6, 2023

Anyone have any tricks or tips to easily understand what script runner scripts are doing? I am analysing a new system which has loads of legacy scripts which I need to figure out if we still need but they are not labelled well at all and I am not yet great at reading groovy. Are there any easy ways to know what's actually meant to be happening?

1 answer

1 accepted

1 vote
Answer accepted
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2023

Oh, now that's a whole new bag of random kittens.

The short answer is "no", you're going to need to read and understand what each one is doing in quite a lot of detail.

There is some good news here though

  • Scripts tend to be consistent, even when written by different people - once you've worked your way through a moderately simple one, you'll find the next one to be a lot easier to read and analyse
  • Use the built-in script registry - that lists all the scripts in use, and if it's used alongside a look at what projects are active/inactive/archived, it can give you a good pointer to defunct scripts
  • Once you've got the hang of it, you'll find skimming them for meaning becomes a lot easier (I think I'm saying "steep learning curve, but when you get to the top of the curve, you'll breeze through the rest")
  • If you have huge numbers of them, bear in mind that you have a support agreement with my lot - we're not just there for when it goes bang, you can ask for help with this.

    I'm also happy to take a look if you want.  I'm not the most expert scripter, but I'm good enough to tell you what most scripts do, help you upgrade them, and say where they're used.  Or say "don't know, but I can find an Adaptavist who does".  Let me know if you would like that help?
Dani Miles
Contributor
January 9, 2023

@Nic Brough -Adaptavist- Many thanks! 

As I will need to become quite good at this, I would love to get a few pointers if you would have time? Although I've only been using Script Runnner for a few months it does feel like a lot can be learnt quite quickly and it is such an amazing tool I would like to understand it better. 

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 9, 2023

I think the main thing is to not try to go through the detail the first time. Getting a feel for what a script is doing does not need a great understanding of each line in it.  You can always come back to a complex line of code if you need to.

Scripts tend to make calls into Jira's Java API, which has javadoc  These are technical, and don't have much explanation, but can be helpful if you don't know what a specific function is doing, and good coders will have used indicative names.  Note that there are different sets for "the platform".  (The platform effectively includes Jira Work Management), Jira Software and Jira Service Management we add on top of the platform, so everything in the platform applies the same to them. 

This means you can usually rely on reading something like:

def linkedIssues = ComponentAccessor.issueLinkManager.getOutwardLinks(issue.id).findAll { it.destinationObject.issueType.name == linkedIssueType }

doing what the code's function names say.  The bit in bold is pure Jira (start at issuelinkmanager if you want to read the example's docs) The variable linkedIssues will contain a list of issues linked to the issue in issue.id which are outward, and the target issue is of whatever type is in the linkedIssueType variable.

There is one thing people trip over a lot though - custom fields are complex and a lot of new scripters don't quite understand what getCustomFieldValue does.  It does indeed get the value of a custom field, but that value could be in a number of different shapes.  Numeric fields will return long objects, date and date/time return timestamp objects, select-lists return "options" (which are objects specific to Jira), and muti-selects return lists of options!  You are likely to see code that can either cope with multiple possible types, or that people have taken the simple route - they know what the field type is already, so they can assume the content is a specific type of data.

Of course, we have documentation, including training, but it's very much aimed at solving problems with SR, not so much "how do I read and update inherited scripts" (but we're working on that)

Another resource might be https://library.adaptavist.com - if you think a script might be doing X, have a look in the library for action X - a code comparison might tell you lots!

Dani Miles
Contributor
February 8, 2023

@Nic Brough -Adaptavist-  can you let me know what is the best way to get support from Adaptavist if I need quick help with a specific script? I was hoping to not have to paste scripts here in the community? I raised an Atlassian Request but they won't help with ScriptRunner I don't think.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 8, 2023

There are a couple of options

Raise a request at https://productsupport.adaptavist.com/servicedesk/customer/user/login?destination=portals

Or I can take a look.  I'm a customer success manager now, it's my job to help people out with our products (but I've done a lot of scripting in the past, and like getting my paws dirty with code).  If you'd prefer to talk to me direct, let me know.  If you are the technical contact on your SR licence, then I should be able to find an email address for you in our licence list.

Dani Miles
Contributor
February 8, 2023

@Nic Brough -Adaptavist- thanks, I raised a request SRJSUP-28721, would be good to chat direct at some point if poss, I am at the start of my scripting life and need any advice I can get especially working out what is going on with all these old pieces of code!

Suggest an answer

Log in or Sign up to answer