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

Transition Validator for one custom field in the screen?

Hello,

How can I make a custom field required on a transition with ScriptRunner?

Let's say the field has the name "xx yyy".

Many thanks in advance.

Leo

1 answer

0 votes

The standard answer is "use a validator" - it should be as simple as saying "customfield 'xx yyy' is not empty", you might not even need a script for it.

You might also be able to do it with a Behaviour, which works on the UI side rather than on the back-end in the workflow with a validator, but that could be a bit more complex to implement and won't catch it if people are using the REST API.

1. The "validator" was already in the question title (see above)

2. There is no "simple validator" on the Server. And I am on the server (see above on the right).

3. Could you post a simple code please?

4. Thanks for your quick reply.

1. Yeah, I just wanted to be clear there were other options

2. Yep, you mentioned Scriptrunner - Jira has a couple of very simple validators built in, but nothing of any serious usefulness.  SR lets you create validators that can do almost everything

3. The pseudo code is really just "if custom field has value, return true".  I don't usually do copy and paste, but in this case, it's easy enough that I can probably do it from memory

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName(customFieldName)
assert customField: "Could not find custom field with name $customFieldName"

if issue.getCustomFieldValue(customField) return true
Like Leo Epstein likes this

@Nic Brough _Adaptavist_ 

Hi Nic,

Thanks a lot for your code.

Could you please inform, what should I change 

1.  to get rid of the following error message?

2. to enter my custom field named "xx yyy"?

error.jpg

Sorry, the "if" query needs to be in braces, so

if (issue.getCustomFieldValue(customField)) return true

On the first line, replace customFieldName with "xx yyy" (with the quotes - that function is expecting a string containing the name of a field)

Like Leo Epstein likes this

@Nic Brough _Adaptavist_ 

Thanks again.

The transition screen cannot be closed though all the fields are not empty.

Can you help please?

1. The code:

def customField = ComponentAccessor.customFieldManager.getCustomFieldObjects(issue).findByName("Wiedervorlage-Datum")

assert customField: "Could not find custom field with name Wiedervorlage-Datum"

if (issue.getCustomFieldValue(customField)) return true

 

2. The two red points on the console:

02.jpg01.jpg

Suggest an answer

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

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

168 views 6 7
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