I'm attempting to set a CqRecord RESOURCE_LIST field with multiple values. I'm using the field format "cq.record:Build/<value>@<DB Name>/<DB Target>", per value that I want to be set/include.
Code example/
CqRecord record;
CqFieldValue buildField;
...
// get all field meta data
Property.List fieldsFinal = record.getAllFieldValues();
// find CQ Fields for updating CQ record later
CqFieldValue cqField = null;
for (Object field : fieldsFinal) {
cqField = (CqFieldValue) field;
String fieldName = cqField.getName();
...
if (fieldName.equals("Builds")) {
buildField = cqField;
List<String> initChoices = new ArrayList<String>(cqField.getChoiceList());
initChoices.remove(0);
buildChoices = initChoices;
}
...
}
...
// update builds
List<String> buildTableValues = ((TableModel) buildTable.getModel()).getRows();
String buildString = "";
for (String build : buildTableValues) {
String buildValue = "cq.record:Build/" + build + CQIntegration.DB_NAME + "/" + CQIntegration.DB_TARGET;
if (buildString.isEmpty()) {
buildString = buildString + buildValue;
} else {
buildString = buildString + "\n" + buildValue;
}
}
// CqFieldValue.initialize() works if I only have one build to set in this field
// buildField.initialize(buildValue);
// CqFieldValue.setMultilineStringValue() doesn't work (or maybe it does?) if I form a multi-line String
// Is this even the correct logic/method to use for setting multiple values in a RESOURCE_LIST type field?
buildField.setMultilineStringValue(buildString);
record.setProperty(buildField.getPropertyName(), buildField);
...
record.doDeliver(null, StpChangeContext.UNORDERED);
...
When there's only one value to set, this works fine by using relatedBuild.initialize();
However, I need to be able to account for multiple values, so I tried using relatedBuild.setMultilineStringValue() after creating a multi-line String with "\n". This produces the exception:
'Property error: The Field "Builds" has multiple entries which do not identify existing entities of type Build:
cq.record:Build/<value>@<DB Name>/<DB Target>
cq.record:Build/<value>@<DB Name>/<DB Target>'
What am I doing wrong? A single value and I'm good. Multiple values, I'm not sure what String format it's expecting or what's exactly going wrong.
I'm open to other tips/criticisms of my approach as well...