Checklist items mapping

If we have a checklist with the values

  • Yes, do not include x
  • Yes, include x
  • No

And we want to transform it the remote systems API which looks like this:

{
  "sync":boolean,
  "include": boolean
}

So to match the above body we need to create a scripted variable.



Code example

import com.atlassian.jira.component.ComponentAccessor
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def SYNC_CF_ID = 26531
def SyncCf = customFieldManager.getCustomFieldObject(SYNC_CF_ID)
def Sync = issue.getCustomFieldValue(SyncCf)

def yesWithoutX = "Yes, do not include x"
def yesWithX = "Yes, include x"
def no = "No"

def includeValue = false
def syncIt = false


if(Sync){
    Sync.each{it->
        if(it.toString() == yesWithoutX)
        	syncIt = false
        else if(it.toString() == yesWithX)
          syncIt = true
        else if(it.toString() == no)
            includeValue = true     
    }
}

class Result{
 String syncIt
 String include
}

return new Result(syncIt:syncIt,include:includeValue)


Use the variable named {{syncCheck}} in the body like this

{
"sync":"{{syncCheck.syncIt}}",
"include":"{{syncCheck.include}}"
}