Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Next challenges

Recent achievements

  • Global
  • Personal


  • Give kudos
  • Received
  • Given


  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Need to auto increment a sequence field on completion of a task

Need to update the value or increment the value in sequence field in below code snippet as follows :

  // Loop through each of the incoming task and add them to the new request
              whTasks.eachWithIndex { task, idx ->
            //  idx = idx + 1
                             oWHTaskNode.@ws_no = task[1].ws_no
                    (" IC : Incoming WT - " + oWHTaskNode.@ws_no)
                             oWHTaskNode.@itemno = task[1].itemno
                    (" IC : Incoming Item - " + oWHTaskNode.@itemno)
                             oWHTaskNode.@lot_number           = task[1].lot_number
                    (" CT WT : LNO = " + oWHTaskNode.@lot_number)
                             oWHTaskNode.@itemno               = task[1].itemno
                    (" CT WT : INO = " + oWHTaskNode.@itemno)
                            oWHTaskNode.@sequence             = "1"
                   (" CT WT : SEQ = " + oWHTaskNode.@sequence)
                             //Since we already have one WHTask node in the Default request, we replace it with the first WHTask from incoming request
                             // Later, other WHTasks will be added in the default request
                             if(idx == 0){
                                           // First task, therefore replace the WHTask in Default (New) request with this
                            //oRequestNew.Body.WarehouseOrderConfirmation.WHOrder.WHTask.replaceNode{ oWHTaskNode }
                                           //Direct replacement of node is not working, so removing the node by replacing with EMPTY and then adding a new node ;-)
                                           oRequestNew.Body.InductionConfirmation.CO.FP.appendNode( oWHTaskNode )                                                                                                    
                             }else {
                                           // Subsequent WHTasks will be added as a new node in the Default (New) request
                                           oRequestNew.Body.InductionConfirmation.CO.FP.appendNode( oWHTaskNode )                                           
                             oWHTaskNode = new XmlSlurper().parseText(whTaskNodeStr)

1 answer

1 vote
Sid Community Leader Apr 02, 2019

Hi @Tia 

Do you need a custom filed with. auto increment of a number with every new issue (task) is created?

if so you can try this, this need a script runner plugin 


Create a text custom field (single line). In the example I added "Numbers" as field name. Then create a postfuntion with the script below. 


import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.jql.parser.JqlQueryParser
import com.atlassian.jira.web.bean.PagerFilter
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue

// get all the used numbers so far
def query = ComponentAccessor.getComponent(JqlQueryParser).parseQuery("project = JA AND 'Numbers' is not EMPTY ORDER BY 'Numbers' DESC")
def results = ComponentAccessor.getComponent(SearchProvider).search(query,ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser(),new PagerFilter(1))
int maxNumbers = 0
CustomField cField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Numbers")

// get the highest used number
for(Issue documentIssue: results.getIssues())

{ maxNumbers = documentIssue.getCustomFieldValue(cField) as Integer }
// set the new number
def newNumbers = ++maxNumbers as String
issue.setCustomFieldValue(cField, newNumbers)

Hello @Sid ,

Can u please provide the updated script as this one is throwing errors(two)-


I am inserting the above code in the post function under custom script and getting these 2 error. Please can you help @Sid 

Suggest an answer

Log in or Sign up to answer

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