// Create statement to select only active custom fields that apply to
// line items.
String statementText =
"WHERE entityType = :entityType and isActive = :isActive LIMIT 500";
Statement filterStatement =
new StatementBuilder(statementText)
.putValue("entityType", CustomFieldEntityType.LINE_ITEM.toString())
.putValue("isActive", true)
.toStatement();
// Set defaults for page and offset.
CustomFieldPage page = new CustomFieldPage();
int offset = 0;
int i = 0;
List<Long> customFieldIds = new ArrayList<Long>();
do {
// Create a statement to page through custom fields.
filterStatement.setQuery(statementText + " OFFSET " + offset);
// Get custom fields by statement.
page = customFieldService.getCustomFieldsByStatement(filterStatement);
if (page.getResults() != null) {
for (CustomField customField : page.getResults()) {
System.out.println(i + ") Custom field with ID \""
+ customField.getId() + "\" and name \"" + customField.getName()
+ "\" will be deactivated.");
customFieldIds.add(customField.getId());
i++;
}
}
offset += 500;
} while (offset < page.getTotalResultSetSize());
System.out.println("Number of custom fields to be deactivated: " + customFieldIds.size());
if (customFieldIds.size() > 0) {
// Modify statement for action.
filterStatement.setQuery("WHERE id IN (" + StringUtils.join(customFieldIds, ",") + ")");
// Create action.
DeactivateCustomFields action = new DeactivateCustomFields();
// Perform action.