Forums

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

Behaviour script regarding "Sprint" field

Andrei Vermesan January 5, 2021

Hello community,

 

I have a question regarding Behaviours from ScriptRunner addon.

Requirement: We need to have a script that has the behaviour of hiding and showing 2 fields that depends of a value from Support level field(see below).

Environment: Jira 7.13.13; Scriptrunner version – 6.5.0

Field 1 – "Support level" with the following values: 1st lvl support/2nd lvl support/3rd lvl support (single choice – custom field)

Field 2 – Story Points (nr field – custom field)

Field 3 – Sprint (Jira Sprint Field)

 

The issue that we have it that the script is working as intended but the part where it needs to set the values to “null” when 3rd lvl support is not selected is not working for Sprint field. For story points its working and the value is set to null. We have tried out also with “0” and “-1” values as int and also string but without any results. If we try to set the FormValue to int “1” then the Sprint Field is showing the first Sprint created, so the function is working but the Null value doesn’t.

 

Question: How can I setFormValue for Sprint field to null? Just to remove the selected sprint if someone choose not to go with 3rd lvl support option.

 

Behaviour script on “Support level” field:

 

import com.atlassian.jira.component.ComponentAccessor

 

if (getFieldScreen().name == "SD: Bug Edit Screen")

{

   

def story = getFieldById("customfield_10006")

def sprint = getFieldByName("Sprint")

def support = getFieldById(getFieldChanged())

 

def selectedOption = support.getValue() as String

def is3rdSelected = selectedOption == "3rd Level Support"

def defaultValue = null

 

if (selectedOption != "3rd Level Support")

{

   story.setFormValue(defaultValue)

   sprint.setFormValue(defaultValue)

  

}

story.setHidden(!is3rdSelected)

story.setRequired(is3rdSelected)

sprint.setHidden(!is3rdSelected)

sprint.setRequired(is3rdSelected)

}

 

Thank you in advance.

 

Best regards,

Andrei

1 answer

1 accepted

0 votes
Answer accepted
Radek Dostál
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, 2021

I get the same results when I try this, but when digging into the form, noticed one thing in the elements.

 

For ease I have debugged this using the field "Summary" and "Sprint".

So if I then do

def summary = getFieldById("summary")

This in elements corresponds to this:

<input class="text long-field" id="summary" name="summary" type="text" value="">

 

But if you look at Sprint, it has a different ID:

<input autocomplete="off" role="combobox" aria-autocomplete="list" aria-haspopup="true" aria-expanded="false" class="text aui-ss-field ajs-dirty-warning-exempt" id="customfield_11910-field" type="text" data-lpignore="true" aria-busy="false">

 

So I tried this and it seems to work:

def formSprint = getFieldByName("Sprint")
def sprintCF = getFieldById("customfield_11910-field")

def summary = getFieldById(getFieldChanged())
def selectedOption = summary.getValue() as String
def is3rdSelected = selectedOption == "3rd Level Support"

if (selectedOption != "3rd Level Support") {
sprintCF.setFormValue(null)
}

 

And voala, that seems to work.

 

So maybe it is a little inconsistent, possibly a one of a kind welcome to Atlassian world kinda field.

I didn't really tinker with this more at this time, that's just what I found out right now.

 

(You can find the Sprint field id either through dev tools -> inspector; or from Custom Fields and just take up the ID from url.)

Andrei Vermesan January 6, 2021

Hello @Radek Dostál ,

I have tried your solution and it's working. First time when I see this form of custom field ID. I have one question if you can help me with it, where did you find those information about the summary and sprint field in detail? With <input and everything?

I ask because it could help me in future regarding other problematic fields if you are kind to share :D

Thank you very much for your answer.

 

Best regards,

Andrei

Andrei Vermesan January 6, 2021

Hello @Radek Dostál ,

I've found the details in the F12 elements. Thank you

Suggest an answer

Log in or Sign up to answer