Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Can I tie my Confluence Questions to a Confluence knowledge base or bases?

Elizabeth Young
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!
August 28, 2014

Can I tie my Confluence Questions to a Confluence knowledge base or bases?

1 answer

1 accepted

Suggest an answer

Log in or Sign up to answer
1 vote
Answer accepted
PD Sheehan
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 Champions.
July 27, 2023

Generally, in Groovy (maybe in Java too) if you need to supply an argument that is defined as "Class... objects" (they are called variable arguments) and your values are in a list or collection, you can expand your list with "as Class[]"

For example

def myFunction(String... args){
//so something with args
}

def listOfStrings = ['a','b','c']

//call myfunction with listOfStrings
myFunction(listOfStrings as String[])

The HAPI "setCustomFieldValue" method has several signatures that you can leverage. 

The simplest one is if you have the String values for each of your options

def hardCodedListOfCheckBoxValues = ['Foo','Bar']
Issues.create('DEMO', issueType){
setSummary("Test 1")
    setCustomFieldValue("Checkbox Field", hardCodedListOfCheckBoxValues as String[])
}

Another approach if you are reading the option (as List<LazyLoadedOption>) from another issue:

import com.atlassian.jira.issue.customfields.option.Option //Option is the parent interface for LazyLoadedOption
def
originalCheckboxValues = issue.getCustomFieldValue("Checkbox Field") //list of LazyLoadedOptions

Issues
.create('DEMO', issueType){
setSummary("Test 2")
setCustomFieldValue("Checkbox Field", originalCheckboxValues as Option[])
}

Another option is to process each item in your Options list in a separate closure:

def originalCheckboxValues = issue.getCustomFieldValue("Checkbox Field") //list of LazyLoadedOptions
def someListOfOptionsToCopy = ['foo','bar']

Issues
.create('DEMO', issueType){
setSummary("Test 2")
setCustomFieldValue("Checkbox Field"){
//here we can itterate over the originalCheckboxValues and perhaps conditionally add them to the issue
originalCheckboxValues.each{originalOption->
if(originalOption in someListOfOptionsToCopy){
add(originalOption) //the 'add' method here is part of HAPI
}
}
}
}

 

Andrew Wolpers
July 28, 2023

Extremely helpful, as always. Thanks for the direction, the LazyLoadedOptions example was exactly what I was looking for.

TAGS
AUG Leaders

Atlassian Community Events