Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Make field mandatory on transition IF other field is NULL

Is it possible to make a custom field mandatory ONLY when another customer field has not been populated (NULL) on a screen.
This will happen on the create transition and i have no idea were to start! 

2 answers

1 vote

You should start with ScriptRunner behaviours. You can find more info here:

https://scriptrunner.adaptavist.com/5.3.0/jira/behaviours-overview.html

You would need to add the custom field which influences the required behaviour of another custom field and write a script for the field.

The script would look something like this

def field1 = getFieldById(getFieldChanged())

def field2 = getFieldByName("customFieldName")

if (field1.getValue() == "your value") {

  field2.setRequired(true)

} else {

field2.setRequired(false)

}

I did not check if the script works, but it s the idea.

In my opinion, it is better to use the validator

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name1"));

if
(CustomFieldValue1 == null) {
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name2"));

if(CustomFieldValue2 == null){
invalidInputException = new InvalidInputException("name2 is mandatory when name1 is null");
}

}

 

Worked perfect thanks Neta. Problem im having now is it works when i create the case, but when i create another case it doesnt?

Once ive published the modified workflows its only lasting one creation if that makes sense?

You added another if case and it does not work? Can you send the script?

So i did a validator on the create transition (Script Validator)....

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID List"));

if(CustomFieldValue1 == null) {
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("Retailer ID"));

if(CustomFieldValue2 == null){
invalidInputException = new InvalidInputException("Retailer ID is mandatory when Retailer ID List is not populated");
}

}

 

What is the problem can you explain ?

I don't understand what you mean when you said "case" I thought you meant you added another if statement..

 

Sorry when i say case i mean issue (blame our users terminology)

I add script to create transition - Publish workflow - Create issue - Works perfect!

Then if i try to create another issue - script hasnt worked

The issue you created has the same WF as the first issue?

You added another condition to the script?

It's not supposed to happen..

Yes the same WF. Its a weird one the fact it works the first time, but then doesnt even though im doing exactly the same thing?

Below are the validators and post functions...

validation_postfunction.jpg

1)Try to add logs to the script

2) Try this:

import com.atlassian.jira.component.ComponentAccessor
import com.opensymphony.workflow.InvalidInputException

def customFieldManager = ComponentAccessor.getCustomFieldManager();
def CustomFieldValue1 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name1")) as String;

if
(CustomFieldValue1 == null && CustomFieldValue1=="") {
def CustomFieldValue2 = issue.getCustomFieldValue(customFieldManager.getCustomFieldObjectByName("name2")) as String;

if(CustomFieldValue2 == null && CustomFieldValue2 ==""){
invalidInputException = new InvalidInputException("name2 is mandatory when name1 is null");
}

}

If it's doesn't work I have no idea why it happens .. I use this script all the time on the create transition this way and did not come across it ..

By adding logs to the script you can know exactly why it's happen.

Is there a chance it could be because one of the fields is a 'JSON Request Custom Field'?

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Staying organized with Jira: best practices for a better project management

Project managers know this problem: A “mountain of work” lays in front of you, and you don’t know how and where to tackle them. Different to-dos lie ahead, but just one task after the other can be ha...

225 views 2 1
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