/
Checklist items mapping

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}}"
}


Related content

Groovy Variables
Groovy Variables
More like this
Mapping of priority
Mapping of priority
More like this
Update Jira custom field examples
Update Jira custom field examples
More like this
Create an issue from response from external system
Create an issue from response from external system
More like this
Mustache Variables
Mustache Variables
More like this
Jira to Jira Sync Demo
Jira to Jira Sync Demo
More like this