Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Scriptrunner behavior does not update form on expected value

Jira Version : 8.8.1
Scriptrunner Version : 6.37.0

I am trying to create a behavior within a transition where when users select a specific value in Resolution field it will hide the listed required fields and remove requirement.
However I the scripts I tried will only trigger upon loading of the transition screen.
Once I selected the expected values ie. Duplicate or Request Cancelled it does not update anymore.

I tried the following scripts.

 

~~Current saved script

def CField1= getFieldByName("Requestor Region")
def CField2= getFieldByName("Platform")

def TCType = getFieldByName("Resolution")
def selectedOption = TCType.getValue() as String


if(selectedOption=="Duplicate")
{
CField1.setHidden(true)
CField2.setHidden(true)
CField1.setRequired(false)
CField2.setRequired(false)
}

else if (selectedOption=="Request Cancelled")
{
CField1.setHidden(true)
CField2.setHidden(true)
CField1.setRequired(false)
CField2.setRequired(false)
}

else if (selectedOption!="Request Cancelled" || selectedOption!="Duplicate")
{
CField1.setHidden(false)
CField2.setHidden(false)
CField1.setRequired(true)
CField2.setRequired(true)
}

 

~~~Other scripts tried
Script 1 : 

if (getActionName().equals("Setup Complete")) {
boolean hidden = (getFieldByName("Resolution")?.getValue()?.toString()?.equals("Duplicate"));
getFieldByName("Platform").setHidden(hidden);
}

Script 2:

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript

@BaseScript FieldBehaviours behaviours

def platform = getFieldById('customfield_14524') //Platform

def components = getFieldById(getFieldChanged()).getValue() as List<ProjectComponent>
def compField = getFieldByName("Resolution")
compField.setAllowInlineEdit(false)

if (components.any {it.name.contains("Duplicate")}) {
platform.setHidden(false)
platform.setRequired(true)
}
else {
platform.setHidden(true)
platform.setRequired(false)
}


I have properly mapped the script since I am able to hide fields upon load upon testing.
I also tried via the initialiser function, nothing updates either.
Is there anything else I need to configure or something missing on my script?

1 answer

0 votes
Pramodh M Community Leader Dec 20, 2021

Hi @Jermaine Aguilar 

Here are troubleshooting methods you can follow

  • Try with getFieldById instead of getFieldByName
  • Try logging the Output of the Field Value when you compare the field value with a string

Thanks,
Pramodh

Hi @Pramodh M 

I tried switching with getFieldById, looks like I am getting null on this part(I got this via developer tools)

def selectedOption = TCType.getValue() as String


As for the logging output, I am having a hard time tracking error log.
I already enabled logging via com.onresolve.jira.groovy (DEBUG) but no entries were made when I went to the log file.

Is there another way to debug the script, like could I make a message prompt like in javascript, or somehow print a message in developer tools console?

Thanks!

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you