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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,546
Community Members
 
Community Events
185
Community Groups

Make field mandatory on transition IF other field is NULL

Rob B
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.
Jan 31, 2018

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
Alexey Matveev
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.
Jan 31, 2018

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.

0 votes
Neta Elyakim
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.
Feb 01, 2018 • edited

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");
}

}

 

Rob B
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.
Feb 01, 2018

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?

Neta Elyakim
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.
Feb 01, 2018

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

Rob B
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.
Feb 01, 2018

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");
}

}

Neta Elyakim
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.
Feb 01, 2018

 

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..

 

Rob B
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.
Feb 01, 2018

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

Neta Elyakim
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.
Feb 01, 2018

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..

Rob B
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.
Feb 01, 2018

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

Neta Elyakim
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.
Feb 01, 2018

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.

Rob B
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.
Feb 01, 2018

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
AUG Leaders

Atlassian Community Events