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());
}
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.
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...
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/
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.