How to reference a Custom Field Value in a Confluence Page

Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 14, 2017

Hi guys,

Im trying to post a custom field value in a Confluence Page when a JIRA issue is created (post function). I tried to do to as follows but it didnt work for me.

 

def cField1 = customFieldManager.getCustomFieldObject("customfield_10008")
def cField2 = customFieldManager.getCustomFieldObject("customfield_10009")
def cField3 = customFieldManager.getCustomFieldObject("customfield_10201")

def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
xml.'ac:structured-macro' ('ac:name': "jira") {
'ac:parameter' ('ac:name': "key", issue.key)
}

// add more paragraphs etc

xml.p ("${issue.getCustomFieldValue(cField1)}")
xml.p ("${issue.getCustomFieldValue(cField2)}")
xml.p ("${issue.getCustomFieldValue(cField3)}")

 

I've imported:

import com.atlassian.applinks.api.ApplicationLink
import com.atlassian.applinks.api.ApplicationLinkService
import com.atlassian.applinks.api.application.confluence.ConfluenceApplicationType
import com.atlassian.jira.issue.Issue
import com.atlassian.sal.api.component.ComponentLocator
import com.atlassian.sal.api.net.Request
import com.atlassian.sal.api.net.Response
import com.atlassian.sal.api.net.ResponseException
import com.atlassian.sal.api.net.ResponseHandler
import groovy.json.JsonBuilder
import groovy.xml.MarkupBuilder
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.IssueManager

 

And the error i recieve is:

2017-09-14 17:18:19,174 ERROR [workflow.ScriptWorkflowFunction]: *************************************************************************************
2017-09-14 17:18:19,174 ERROR [workflow.ScriptWorkflowFunction]: Script function failed on issue: SMP-19, actionId: 1, file: <inline script>
groovy.lang.MissingPropertyException: No such property: customFieldManager for class: examples.docs.Script226
	at examples.docs.Script226.run(Script226.groovy:50)

 

Im really stuck here, can someone help me? thanks in advance.

1 answer

1 accepted

1 vote
Answer accepted
Thanos Batagiannis _Adaptavist_
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.
September 15, 2017

hey Alejandro, 

You will need, after the imports, something like 

def customFieldManager  = ComponentAccessor.customFieldManager
Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 18, 2017

Thank you Thanos, It worked perfectly

Alejandro Suárez - TecnoFor
Marketplace Partner
Marketplace Partners provide apps and integrations available on the Atlassian Marketplace that extend the power of Atlassian products.
September 18, 2017

Hi Thanos,

 

I resolved the problem with your suggestion but now i want to "italic" the text, and I dont know how to do it, I tried to search something similar in the web but with no luck.

 

Can you help me with this? (I tried this code below)

xml.p ("<em>${issue.getCustomFieldValue(cField1)}"</em>")
xml.p ("<em>${issue.getCustomFieldValue(cField2)}</em>")
xml.p ("<em>${issue.getCustomFieldValue(cField3)}</em>")

Suggest an answer

Log in or Sign up to answer