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

Script for sorting values in a customfield

I have a single select customfield that loads new values from a csv file on a schedule (midnight each night).  When the values are loaded they show at the top of the list, so I am looking for a separate script that I can run on a schedule (1AM each morning) that will sort the values in the aforementioned customfield.  Has anyone had any success doing something like this?

 

For reference, here is the entire script that we have configured to run as a job in Scriptrunner:

//JIRA_Pcode PROD
import java.text.SimpleDateFormat
import java.util.regex.*
import org.apache.commons.io.FileUtils;
import java.io.FileNotFoundException;
import java.io.IOException;
import com.atlassian.jira.component.ComponentAccessor;
import com.csvreader.CsvReader;
def date = new Date()
def yesterday = date - 1
def sdf = new SimpleDateFormat("yyyyMMdd")
def a = sdf.format(date)
def b = sdf.format(yesterday)
def c = "//[hostname]/pjira/cappm_jira_clarityProject_" + b + ".csv"

def issue = ComponentAccessor.getIssueManager().getIssueObject("SCRUM-3")
def customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Project P-Code")
def fieldConfig = customField.getRelevantConfig(issue)
def optionsManager = ComponentAccessor.getOptionsManager()
def options = optionsManager.getOptions(customField.getRelevantConfig(issue))

CsvReader products = new CsvReader(c);
products.readHeaders();
while (products.readRecord())
{
def id = products.get("ID");
def project = products.get("Project");
def time_entry = products.get("Open for Time Entry");
def clarity = products.get("Clarity Project");
def action = products.get("Action");
optionsManager.getOptions(fieldConfig).each {
if((it.value == clarity) && (time_entry.equalsIgnoreCase('Y')) && (action.equalsIgnoreCase("UPDATE"))){
optionsManager.enableOption(it)
return}
else if((it.value == clarity) && (time_entry.equalsIgnoreCase('N')) && (action.equalsIgnoreCase("UPDATE"))){
optionsManager.disableOption(it)
return}
else if((it.value.startsWith("P000")) && (it.value.substring(0, 9) == id) && (it.value != clarity) && (time_entry.equalsIgnoreCase('N')) && (action.equalsIgnoreCase("UPDATE"))){
optionsManager.disableOption(it)
optionsManager.setValue(it, clarity)
return}
else if((it.value.startsWith("P000")) && (it.value.substring(0, 9) == id) && (it.value != clarity) && (time_entry.equalsIgnoreCase('Y')) && (action.equalsIgnoreCase("UPDATE"))){
optionsManager.enableOption(it)
optionsManager.setValue(it, clarity)
return}
}
if (action.equalsIgnoreCase("INSERT") && (time_entry.equalsIgnoreCase('Y')))
{
if (optionsManager.getOptions(fieldConfig).value.contains(clarity))
{
log.error (clarity + ' ----' + " option exists")
}
else optionsManager.createOption(fieldConfig, null, null, clarity)
log.error (clarity + '----' + "value added")
}
else if (action.equalsIgnoreCase("INSERT") && (time_entry.equalsIgnoreCase('N')))
{
if (optionsManager.getOptions(fieldConfig).value.contains(clarity))
{
log.error (clarity + ' ----' + " disabled option exists")
}
else optionsManager.createOption(fieldConfig, null, null, clarity)
log.error (clarity + '----' + "value added")
optionsManager.getOptions(fieldConfig).each{
if ((it.value == clarity) && (time_entry.equalsIgnoreCase('N'))
&& (action.equalsIgnoreCase("INSERT"))){
optionsManager.disableOption(it)}}
}
}
products.close();
File srcFile = new File(c)
File destDir = new File ("//[hostname]/pjira/jiradata/Spark Integration/processed")
FileUtils.moveFileToDirectory(srcFile, destDir, true)

 

We tried incorporating the following, but it causes the script to run for an extremely long time.

optionsManager.getOptions(fieldConfig).each{options.sortOptionsByValue(null)}

Also open to any recommendations on improvements to the script.

0 answers

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
SERVER
VERSION
8.5.4
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...

210 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