Scriptrunner behavior does not update form on expected value

Jermaine Aguilar December 20, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
December 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

Jermaine Aguilar December 20, 2021

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