Script Runner how to populate scripted field with text string based on number value in another field Edited

Hi,

I'm new to Script Runner and don't know the syntax of the coding well yet.  I have successfully created one scripted field which is calculating/getting a number value.  I'd like to now look at that field and populate another field based on the number to be able to track on-time delivery metrics.  So for example, if my number in my first field is negative, (<0) i'd like the second scripted field to prepopulate with the text string "early" or if the first field =0, my second field would populate as "on-time".  >0 but < 21 would = "1-20 days late" etc.  

I don't see much of a reference to how to set this up.  Any help or direction much appreciated.  

Here's what i've started with... but it's not recognizing my syntax and i don't know where to confirm how it should be.

1 answer

0 vote

At a glance, your code looks broadly ok.

There's a couple of neat tricks with scripted fields though.  If you edit their scripts in-line, there is a basic syntax checker built in.  So you'll get told if your code is not going to work.

Beneath the code entry box, there's also a preview option, where you fill in an issue to try the script against, repeatedly.  So set up two test issues, one with your numeric field set to 42 and the other with -4 or something, then you can test for both cases.

Also, you might want to check that the output type is set to text, as that's what you are currently returning.

Hi Nic,

I agree, the syntax and issue preview are helpful. i've made some additional changes to the code and am really close... i think.  I also do think i'm setting my output to text.  Here's what i've got now and the error i'm getting.  

Does anything jump out as being wrong?  Am i missing a bracket or is something bigger not defined?  

1PARE.PNGPAR.PNG

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Published Apr 19, 2018 in Marketplace Apps

Calling all developers––You're invited to Atlas Camp 2018

 Atlas Camp   is our developer event which will take place in Barcelona, Spain  from the 6th -7th of   September . This is a great opportunity to meet other developers and get n...

366 views 0 6
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