Forums

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

Create object with attributes as reference

Abhimanyu Gadroo
October 3, 2017

I'm using insight custom field and insight referenced custom fields in my project. In the project i have added a groovy script to create object in insight as soon as issue is created. Following code :

def cfObjectTypeAttributeBean = objectTypeAttributeFacade.loadObjectTypeAttributeBean(312); 
def cfObjectAttributeBean = newObjectBean.createObjectAttributeBean(cfObjectTypeAttributeBean); t
def cfObjectAttributeValueBean = cfObjectAttributeBean.createObjectAttributeValueBean();
cfObjectAttributeValueBean.setTextShortValue(issue.getCustomFieldValue(ComponentAccessor.getCustomFieldManager().getCustomFieldObject(10247)).toString());

values = cfObjectAttributeBean.getObjectAttributeValueBeans();
values.add(cfObjectAttributeValueBean); // Add the value to the object attribute
cfObjectAttributeBean.setObjectAttributeValueBeans(values);

objectAttributeBeans.add(cfObjectAttributeBean); // Add to the list of object attributes
}

/* Set all object attributes to the object */
newObjectBean.setObjectAttributeBeans(objectAttributeBeans);

/* Store the object into Insight. The new ObjectBean will be updated with an unique ID */
try {
newObjectBean = objectFacade.storeObjectBean(newObjectBean);
log.warn("newObjectBean: " + newObjectBean);
} catch (Exception vie) {
log.warn("Could not create issue due to validation exception:" + vie.getMessage());
}

 Capture.JPG

The Overall results is as above. However i want the system attribute to be referenced with system ID. If i change the attribute type to object it runs without any error but no output is there.

2 answers

Suggest an answer

Log in or Sign up to answer
1 vote
Martin Bayer _MoroSystems_ s_r_o__
Community Champion
September 7, 2021

Hi @Sanjana Nalam , welcome on the community. Do you really need to access the CSV as DB tables? I think it is valid for complicated CSV files and I never used it to be honest.

We use following library to read CSV files in groovy:

https://github.com/xlson/groovycsv

 It is really simple to use it...

0 votes
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.
September 9, 2021

I like opencsv for this:

Here is a simple implementation

import com.opencsv.CSVReader

@Grapes(
@Grab(group='com.opencsv', module='opencsv', version='5.5.2')
)

def reader = new CSVReader(new FileReader(new File('path to csv')))

def csvAsArrayOfMaps = reader.collect { it }.with { rows ->
def header = rows.head()
def dataRows = rows.tail()

dataRows.collect { row ->
[header, row].transpose().collectEntries()
}
}

 This this, if you file contains something like this:

colA,colB,colC
1,value1b,value1c
2,value2b,value2c

You can get the total number of rows with "csvAsArrayOfMaps.size()"

And you can get any of the rows with "csvAsArrayOfMaps[rowIndex]"

And you can get a specific column with csvAsArrayOfMaps[0].colB == 'value1b'

There are other fancier methods like "CsvToBeanBuilder" and CSVReaderHeaderAware, but I found the simplest case to be the easier to use.

More info available here: http://opencsv.sourceforge.net/

TAGS
AUG Leaders

Atlassian Community Events