How to generate a new folder, a new item and put this item in the folder?
In a newly created document (quote/rebate/contract) in the prephase I need to generate a new folder, generate a new line item and put this line item into the folder.
What I tried and it did not work:
Using the Structure classes (e.g. ContractStructure), but when the folder is created, the
addFolder
method does not return parentId that is necessary formoveItem
(and there seems to be no other method in ContractStructure to do it any other way).Using the CalculableLineItemCollectionBuilder (cProcessor/quoteProcessor/raProcessor), but again
addFolder
returns void so there is no way of knowing the parentId directly.
Solution:
//Example for Contracts, use appropriate Structure object for your use case (ContractStructure, RebateAgreementStructure, CompensationStructure, QuoteStructure)
protected ContractStructure createDefaultContractFolderStructure() {
String myFolderLabel = "Default Folder"
String myLineItemConditionTypeName = "Default Condition Type"
ContractStructure contractStructure = new ContractStructure()
ContractStructure.Item folder = contractStructure.addFolder(myFolderLabel)
ContractStructure.Item item = contractStructure.createItem(myLineItemConditionTypeName)
folder.items = [item]
return contractStructure
}
This code snippet creates a new folder and puts items into it. The trick is not to use moveItem
method but do it directly. It works even on empty documents.
Found an issue in documentation? Write to us.