cancel
Showing results for 
Search instead for 
Did you mean: 

How to add item to AssociativeCollection

Former Member
0 Kudos

Hi, experts!

Faced a problem while adding ContractDocuments to MA. Here is my code:

AssociativeCollectionIfc srcContractDocuments = src.getContractDocuments();

AssociativeCollectionIfc destContractDocuments = destination.getContractDocuments();

for (int i = 0; i < srcContractDocuments.size(); i++) {

ContractDocumentIBeanIfc srcContractDocument = (ContractDocumentIBeanIfc) srcContractDocuments.get(i);

ContractDocumentIBeanIfc destContractDocument = (ContractDocumentIBeanIfc) destContractDocuments.create();

copyContractDocument(srcContractDocument, destContractDocument);

destContractDocuments.add(destContractDocument);

}

copyContractDocument copies all the fields - most likely it is correct. But when i save destination ContractDocuments, they are empty. I've iterated through destContractDocuments with for-loop after copying - it contains all necessary documents, but they are missed after saving. I've looked some sources and found this method in AssocCollnBoIfc (it is actually used while calling AssociativeCollectionIfc.add()):

/**

  • Adds a new bo to the collection without first saving to the database.

  • The bo will instead be saved when the parent saves it collection. (Assuming that either

  • the associate lifecycle has been coupled or postSave or preSave has been implemented).

*/

public void addAndSaveLater(PersistentBo pbo) throws ApplicationException, DatabaseException;

So, my problem is that i do not know, how to save AssociativeCollection through IAPI. Are there some variants?

Best regards, madhead

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Guess some of the key system attributes of the object might not be set in the copy method used (e.g. parent object id, parent collection id etc..).

Use destContractDocuments.createFromAnother(srcContractDocument). This would do a deep copy as it is done in "document duplicate" and probably would satisfy you needs.. You can always overwrite the values calling destContractDocuments.setXXX() methods after a framework copy.

Thanks, Baski

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello, Baski

The problem is that i do not need a deep copy, i need to manually set a few of them. And all the required fields are set (if they are not - i got validation exceptions)

Best regards, madhead

Former Member
0 Kudos

Hi,

Just to carify my previous comment, the copy done in createFromAnother() is neither shallow nor deep as the Java object copy. It has some application logic to it signfying which field/collection should be copied.

if framework copy doesn't suit you, then here are few questions to ponder upon:

- For adding contract documents; you have to create a couple of collection entries to make it work:

Attachment yourAttachment =...

DocumentVersionBo docVersions = (DocumentVersionBo) contractDoc.getDocVersions().create();

docVersions.setDoc(yourAttachment);

contractDoc.getDocVersions().add(docVersions);

CheckOutInfoBo outbo = (CheckOutInfoBo) contractDoc.getCheckOutInfo().create();

contractDoc.getCheckOutInfo().add(outbo);

getContractDocuments().add(contractDoc);

Good luck..

Baski

Former Member
0 Kudos

Thanks, Baski.

I've already solved my problem. It was incorrect Checkout Info fields replication.