Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Update field as mandatory based on previous field using Scruipt runner

I am new to Script Editor. I added the script, but doesn't look like it is working.

I added new behavior, added the field(radio button) and added Service side script. My environment is JIRA server. Any help is much appreciated. I am missing any configuration setting for the 1st time use?

 

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def CauseCodeField = getFieldByName("TEST SK DropDown Field")
def CurrentField = getFieldById(getFieldChanged())

def selectedOption = CurrentField.getValue() as String
def isYesSelected = selectedOption == "Yes"

CauseCodeField.setRequired(isYesSelected)

2 answers

Your scripts look valid, try to print the log to check it:

import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.issue.priority.Priority
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def CauseCodeField = getFieldByName("TEST SK DropDown Field")
def CurrentField = getFieldById(getFieldChanged())

def selectedOption = CurrentField.getValue() as String
def isYesSelected = selectedOption == "Yes"

log.warn "CurrentField: " + CurrentField
log.warn "selectedOption: " + selectedOption
log.warn "isYesSelected: " + isYesSelected

CauseCodeField.setRequired(isYesSelected)

Check your atlassian-jira.log if the value is true. You can read more here how to get the log file. https://confluence.atlassian.com/adminjiraserver/logging-and-profiling-938847671.html

Thank you. Let me check the log.

Since its the Radio button, the behavior is expected to work when the value in the field is changed I assume.

Since this is new installation of Plug-in, is there any 1st time settings needs to be done so this works for my project and in my environment?

Thanks in advance for your help and time.

Since its the Radio button, the behavior is expected to work when the value in the field is changed I assume.

By default the radio button's value is None. Make sense why you need to change the radio button field value to "Yes" to make it required.

What is your requirement?

Hi, When the value "Yes" is selected, I like to have next field ( dorp down type field) as mandatory. Default value for the drow down field is 'none'.

Also, appreciate if you can let me know how do I search the log file.

Could not see any data logged in the log file. When I search, I could not see it.

This is the script that I use and tested, you can change is a per your requirement:

/**
* Set custom field hidden/required
*/

def changedCF = getFieldById(getFieldChanged()) // Radio button A
def custField1 = getFieldById("customfield_10115") // num1 field
def changedCFValue = changedCF.getValue() as String

//Check if not null and equal to "No"
if (changedCFValue && changedCFValue.equalsIgnoreCase("No")) {

//Set hidden, not required, and null value, if value equal to "No"
custField1.setHidden(true)
custField1.setRequired(false)
custField1.setFormValue(null)

//Other than "No"
} else {

//Set not hidden, required, if value not equal to "No"
custField1.setHidden(false)
custField1.setRequired(true)

}

Screenshot 2020-10-13 at 8.39.22 AM.png

0 votes
Leo Community Leader Oct 09, 2020

Hi @Suresh Srini

I recently encountered such situation. when we add behaviour for checkbox/radio button or select list types it works with selected value ID instead of name(not sure the situation is same for you too)

if so you can modify your script as below

def required= getFieldById(getFieldChanged()).formValue as String == "12345" 
//here 12345 is ID of the value "Yes". you can get this ID in URL tab by editing the value in field context


def CauseCodeField = getFieldByName("TEST SK DropDown Field").setRequired(required)

 

BR,

Leo

Thanks Leo. I tried this as well. But not seems to be working.

Something else blocking it not to work.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
TAGS
Community showcase
Published in Jira Service Management

Why upgrade to Jira Service Management Premium?

We often have questions from folks using Jira Service Management about the benefits to using Premium. Check out this video to learn how you can unlock even more value in our Premium plan.  &nb...

189 views 1 6
Read article

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