Here is the problem I'm facing.
I have an object called attachment, that has repeating attributes doctitle, revision and name, and file attachment. The file attachment is a PDF.
I have created a form based on this attachment.
If there are 3 rows that have been added into the form, I need to do the following:
Take each row's elements. Based on the name, I need to store an attachment document with the pdf file as content, and the fields as metadata.
As things were getting complicated, I created a separate type called attachdoc, that has the same fields as the above. The separate documents are being created, 3 in the above example. However, due to not saving correctly in the TBO, my main attachment object is not being saved properly, and the fields are coming out as empty in the main attachment object [but not in the attachdoc object; that is being saved correctly].
Below is my sample TBO code:
protected void doSave(boolean saveLock, String versionLabel,
Object[] extendedArgs) throws DfException {
boolean bret = isNew();
String folderpath = "";
// aj_document_number
// doc_classification
// doc_status
// doc_title
// letter_type
// revision
// transmittal_docid
int count=0;
count=getValueCount("aj_document_number");
System.out.println(getObjectId() + " doSave Called " + isNew()
+ " lock: " + saveLock + " arg1: " + versionLabel);
boolean AlreadySaved = false;
if (!AlreadySaved)
{
for (int i = 0; i < count; i++)
{
if (!getRepeatingString("aj_document_number", i).equals(""))
{
folderpath = "/Designs/" + GetDocPath(getRepeatingString("aj_document_number", i));
{
try
{
createFolders(folderpath);
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
IDfDocument origcontfile = (IDfDocument) this.getSession().getObject(new DfId(getRepeatingString("r_object_id", i)));
IDfDocument contfile = (IDfDocument) this.getSession().newObject("attach_doc");// .getObject(new DfId(getRepeatingString("r_object_id", i)));
IDfId fId = origcontfile.getFolderId(0);
IDfFolder folder = (IDfFolder) getSession().getObject(fId);
origcontfile.unlink(folder.getFolderPath(0));
origcontfile.link("/data" + folderpath.trim());
contfile.link("/data" + folderpath.trim());
IDfId sysobjID = new DfId(getRepeatingString("thecontentfile", i));
IDfSysObject sysObj = (IDfSysObject)this.getSession().getObject(sysobjID);
ByteArrayInputStream bis = sysObj.getContent();
ByteArrayOutputStream baos = new ByteArrayOutputStream ();
while (bis.available() !=0) {
baos.write(bis.read());
}
contfile.setContentType(sysObj.getContentType());
contfile.setContent(baos);
contfile.setObjectName(getRepeatingString("aj_document_number", i));
contfile.setString("aj_doc_number", getRepeatingString("aj_document_number", i));
contfile.setString("doc_status", getRepeatingString("doc_status", i));
contfile.setString("doc_classification", getRepeatingString("doc_classification", i));
contfile.setString("doc_title", getRepeatingString("doc_title", i));
contfile.setString("revision", getRepeatingString("revision", i));
contfile.setString("origattachid", getRepeatingString("r_object_id", i));
origcontfile.setRepeatingString("aj_document_number", i, getRepeatingString("aj_document_number", i));
origcontfile.setRepeatingString("doc_status", i, getRepeatingString("doc_status", i));
origcontfile.setRepeatingString("doc_classification", i, getRepeatingString("doc_classification", i));
origcontfile.setRepeatingString("doc_title", i, getRepeatingString("doc_title", i));
origcontfile.setRepeatingString("revision", i, getRepeatingString("revision", i));
try {
bis.close();
baos.close();
contfile.save();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
WriteToFile(stack2string(e));
}
}
//}
IDfId fId = this.getFolderId(0);
IDfFolder folder = (IDfFolder) getSession().getObject(fId);
this.unlink(folder.getFolderPath(0));
this.link("/data" + folderpath.trim());
}
}
AlreadySaved = true;
}
if (isNew()) {
super.doSave(saveLock, versionLabel, extendedArgs);
}
}
All help appreciated in this regard.