Database Values custom field custom field accessible from xporter templates?

Jeff Turner August 2, 2015

Greetings,

I am using the Database Values plugin to import tabular data into JIRA issues. For instance, data about a 'Client' associated with an issue:

Screenshot.png

I'd now like to use Xporter to generate PDFs incorporating this client info.

The getCustomFieldValue() output of this custom field is actually an java.util.ArrayList, where each value is an ArrayList containing two Strings, a key and a value. In pseudocode:

Client Info = [
    ["Client name (legal)", "Sample Client Inc."],
    ["Client name (short)", "sampleclient"],
    ["Technical Contact First Name", "Joe"],
    ["Technical Contact Last Name", "Bloggs"],
    .....
]

Is it possible to access the values of such a custom field structure in Xporter templates? I've tried ${Client Info.Client name (legal)} but that doesn't work.

 

Thanks,
Jeff

 

6 answers

1 accepted

2 votes
Answer accepted
Deleted user August 3, 2015

Hi @Fábio Antunes,

Thanks for the pointer, I figured out a solution. I wrote a Groovy scripted field that exposes the table's data as a Javascript. The Groovy script is:

// Groovy scripted field to expose a Database Value custom field (tabular data)
// as a Javascript hash.
// https://answers.atlassian.com/questions/23758594/answers/23759060
import com.atlassian.jira.component.ComponentAccessor
import groovy.json.JsonOutput
cf = ComponentAccessor.customFieldManager.getCustomFieldObject(10502) // Client Info
cfVal = issue.getCustomFieldValue(cf)
valMap = cfVal.inject([:]) { result, item -> result[item[0]] = item[1]; result; }
return JsonOutput.toJson(valMap)

This returns text of the form:

{"TITLE":"VAL", "Client name (legal)":Sample Client Inc.", ....}

Since my Database Values field is called Client Info, I named this scripted field Client Info JSON. Then in my xporter template, I use it with:

Hello %{ var
info = ${Client Info JSON}; info[“Billing
Contact First Name”]},

 

Regards,
Jeff

1 vote
Fábio Antunes August 3, 2015

Hi Jeff Turner,

 

Great Solution, glad to know that everything is working as expected. 


Kind Regards,
Fábio Antunes 

1 vote
Fábio Antunes August 3, 2015

Hi Jeff Turner

 

Yes, in order to help you select the pretended data.


Kind Regards,
Fábio Antunes 

1 vote
Fábio Antunes August 2, 2015

Hi @Jeff Turner

 

Currently Xporter for JIRA does not support Database Values plugin and for that reason it is not possible to access the values that way. The workaround is use javascript to get the data from the value returned by the custom field.

Could you perform an export of that custom field and paste here the generated value to the exported file ?

Kind Regards,
Fábio Antunes 

0 votes
Bartha Norbert September 4, 2015

Hi,

I use also xporter and crm for JIRA. When i export the custom dictionary - custom field it gives me the dictionary field id number (not the value, fo example not the user name just that id number).

Does anyone have idea?

0 votes
Jeff Turner August 3, 2015

Hi Fábio,

Thanks for the help. When you say generate an "export", do you mean the text that ${Client Info} expands to? With the idea being that the text can be parsed with Javascript?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events