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

Tia
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 1, 2019

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
                             log.info (" IC : Incoming WT - " + oWHTaskNode.@ws_no)
                             
                             oWHTaskNode.@itemno = task[1].itemno
                             log.info (" IC : Incoming Item - " + oWHTaskNode.@itemno)
                             
)
                             
                             oWHTaskNode.@lot_number           = task[1].lot_number
                             log.info (" CT WT : LNO = " + oWHTaskNode.@lot_number)
                             
                             oWHTaskNode.@itemno               = task[1].itemno
                             log.info (" CT WT : INO = " + oWHTaskNode.@itemno)
                             
                            oWHTaskNode.@sequence             = "1"
                            log.info (" 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.WS.replaceNode{}              
                                           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
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 2, 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
import com.atlassian.jira.issue.search.SearchProvider

// 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)

Priyanka khare January 11, 2021

Hello @Sid ,

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

1.PNG2.PNG



Priyanka khare January 11, 2021

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
TAGS
AUG Leaders

Atlassian Community Events