You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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!
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");
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You added another if case and it does not work? Can you send the script?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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");
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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..
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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...
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there a chance it could be because one of the fields is a 'JSON Request Custom Field'?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.