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

I have this script but I want to customize it as per the requirement below-

Hello,

 

I have this script but I want to customize it as per the requirement below-

 

 

I want that if my issue (for example ABC-103 is having the issue rank- 5) is moved/transitioned to production then the issue (whichever it is with issue rank -6 ) should change its value from 6 to 5.

similarly, if an issue ABC-110 (any random issue) moves to production with an issue rank say -10 the issue with issue rank -11 must change its issue rank to 10.

 

 

 

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.ModifiedValue;

String String = "Select List";
DefaultIssueChangeHolder changeHolder = new DefaultIssueChangeHolder();
CustomFieldManager CustomFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = CustomFieldManager.getCustomFieldObjectByName(String);

def availableOptions = ComponentAccessor.optionsManager.getOptions(cf.getRelevantConfig(issue))

// find the custom field option valuedef currValue = availableOptions.find { it == issue.getCustomFieldValue(cf) }

// convert the option value to a long data typedef optionValue = Long.valueOf(currValue.toString())

// decrement the valueLong newValue = optionValue-1;

// find the option value that match the decrement valuedef optionToSet = availableOptions.find { it.toString() == newValue.toString() }

// update the new option if foundif(optionToSet)
{
  cf.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(cf),optionToSet), changeHolder);
}

 

1 answer

1 accepted

0 votes
Answer accepted

Hi @Priyanka khare just trying to get more information. So the use case is, you have list of tasks (sorted by issue rank)

  • ABC-2 (rank = 1)
  • ABC-4 (rank = 2)
  • ABC-3 (rank = 3)
  • ABC-1 (rank = 4)
  • ABC-5 (rank = 5)
  • ABC-6 (rank = 6)
  • ABC-7 (rank = null)

When ABC-1 goes to production, list is changed to

  • ABC-2 (rank = 1)
  • ABC-4 (rank = 2)
  • ABC-3 (rank = 3)
  • ABC-5 (rank = 4)
  • ABC-6 (rank = 5)
  • ABC-7 (rank = null)
  • ABC-1 (rank = null)

Is it correct?

Hello, @Martin Bayer _MoroSystems_ s_r_o__ , yes I am trying to achieve exactly that.

Let me know if you have any solution.

 

Thanks in advance.

 

Regards,

Priyanka

Hi @Priyanka khare , are you working with Jira API? I do not have solution for this exact problem. It is not so complicated so I will just try to describe what is the necessary to do (with short code snippets) and you can ask for more help if you can't make it, ok? :)

  1. you need to find all the issues which has any value in field Select list
  2. you need to sort the issues based on the Select list value
  3. forEach the collection of sorted issues
  4. if issue which is current for forEach is equals to current issue (which executes postfunction)  you need to clean the value of the Select list field (set to null)
  5. for other issues you need to decrease the value of Select list field

hello @Martin Bayer _MoroSystems_ s_r_o__ ,

 

Thank you so much for the code snippet,

 

Do u think the script below is going in the right direction in anyway-

import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.bc.issue.search.SearchService
import com.atlassian.jira.issue.ModifiedValue;


SearchService.ParseResult parseQuery(ApplicationUser searcher,
String query)

jqlSearch = '" Project Ranking" is not EMPTY'
parseResult = searchService.parseQuery(user, jqlSearch)


if (parseResult.isValid()) {
def searchResult = searchService.search(user, parseResult.getQuery(), PagerFilter.getUnlimitedFilter())
issues = searchResult.issues.collect {issueManager.getIssueObject(it.id)}
} else {
log.elog("Invalid JQL: " + jqlSearch)
return (1)
}

 

I am new to scriptrunner and groovy and would like to seek your help in-

  1. you need to sort the issues based on the Select list value
  2. forEach the collection of sorted issues
  3. if issue which is current for forEach is equals to current issue (which executes postfunction)  you need to clean the value of the Select list field (set to null)
  4. for other issues you need to decrease the value of Select list field

can u provide me any referenced document for the points you have suggested here? I tried to find the code snippets for the same but did not find any,

 

any help would be highly appreciated.

 

Regards,

Priyanka

Hi @Priyanka khare , I'm really sorry but unfortunatelly I do not have enough time to write the whole script.

You can get a lot of resources on following web pages:

I hope, you will find out this resources usefull. Get back to this thread when you have something at least partially working. We can fix small mistakes/bugs together.

Suggest an answer

Log in or Sign up to answer
TAGS

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