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

What is the best strategy for ensuring that no 2 values of a custom field are the same (database custom field?)

Brian Bishop Sep 25, 2015

I am loading item numbers from a foreign database, into a JIRA custom field.  I would like the user to be able to create new values (that match a regex) but that do not collide with existing item numbers, be they loaded from the initial import, or created using the JIRA interface post-import.  These item numbers (eg 123456A or 889923BB) need to be unique across all projects (or even better, multiple projects but not all). The numbers could be auto-increment but large swaths of numbers in the 6 digit range have already been used.

 

Any thoughts on the best practice for doing something like this?

3 answers

1 accepted

3 votes
Answer accepted
JamieA Sep 27, 2015

but large swaths of numbers in the 6 digit range have already been used

Why don't you just insist on a 7-digit alpanumeric then...  for a simple scripted validator it would be something like:

(cfValues["Name of field"] =~ /\d{7}[A-Z]}/).matches()

(untested)

Brian Bishop Sep 28, 2015

I like the simplicity of the simple scripted validator. {code} (cfValues["Item #"] =~ /\d{6}[A-Z]?/).matches() {code} This does prevent creating issues with an item number that doesn't match 6 numbers and zero or one letters. Would a second simple script validator allow me to disallow the creation of an issue with an Item # that already exists?

JamieA Sep 28, 2015

yes but slightly (but not much) more tricky... you need to execute a jql query with the item value and make sure you don't get any hits other than the current issue (potentially).

Brian Bishop Sep 28, 2015

Yep, thats a very quick solution. It'd be nice if I could suggest the next number, but there some arcane and inane business rules that have governed the Item # historically. I'd rather not bother figuring out how to enforce those rules in the system, so the prevention of duplication is good enough for now.

0 votes
Sumit Kumar Sep 25, 2015

what exactly is meant by database custom field ?

 

any field from a plugin ?

 

Thanks,

Sumit

Brian Bishop Sep 25, 2015

Hi Sumit, https://marketplace.atlassian.com/plugins/org.deblauwe.jira.plugin.database-values-plugin is one of the plugins i was referring to when I said database custom field. Though that might be a way to implement this.

0 votes

@Brian Bishop

I'd say the best way would be to leverage the old built in sequencing value creator and append the sequence value to each custom field value in the field. The call to reference the old sequence api was very simplistic - a single line call worked taking a single string parameter which identified the sequence value.

The table used in the database (JIRA database) is sequence_value_item. If you'd like a bit of example code I'll dig some up and edit this answer - let me know.

-wc

William Crighton

Capital City Consultants

ok, perhaps 'best' way is a _bit_ pretentious...must more accurate would be to say 'one way'

Brian Bishop Sep 28, 2015

Thanks William, I've gone with a couple of validators to prevent duplication, rather than the more elaborate solution you suggested.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Next-gen

Introducing subtasks for breaking down work in next-gen projects

Teams break work down in order to help simplify complex tasks. This is often done iteratively, with tasks being broken down into smaller tasks and so on until the work is accurately captured in well-...

951 views 12 15
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