Gentita ayuda, estoy tratando de anexar documntos pdf, xml a sap b1 y me lanza error -5002, al tratar de usar el .add()
private boolean agregarAnexoDocumento(Transaccion transaccion, Path documentPath, ICompany sociedad) throws SBOCOMException {
IAttachments2 iAttachments2;
String objType = transaccion.getFEObjectType();
int docEntry = transaccion.getFEDocEntry().intValue();
if (!sociedad.isInTransaction().booleanValue())
sociedad.startTransaction();
IDocuments documents = SBOCOMUtil.getDocuments(sociedad, Integer.valueOf(Integer.parseInt(objType)), Integer.valueOf(docEntry));
int idAttachments = documents.getAttachmentEntry().intValue();
boolean isAnexoEmpty = false, isOverride = false;
if (idAttachments == 0) {
iAttachments2 = SBOCOMUtil.newAttachments2(sociedad);
isAnexoEmpty = true;
} else {
iAttachments2 = SBOCOMUtil.getAttachments2(sociedad, Integer.valueOf(idAttachments));
}
String rutaDocumento = documentPath.toString();
String baseName = FilenameUtils.getBaseName(rutaDocumento);
String extension = FilenameUtils.getExtension(rutaDocumento);
String parentPath = documentPath.getParent().toString();
int count = iAttachments2.getLines().getCount().intValue();
if (count == 1 && isAnexoEmpty) {
iAttachments2.getLines().setCurrentLine(Integer.valueOf(0));
} else {
int documentPosition = findDocumentPosition(iAttachments2, baseName);
isOverride = (documentPosition != -1);
iAttachments2.getLines().setCurrentLine(Integer.valueOf(isOverride ? documentPosition : (count - 1)));
}
if (!isAnexoEmpty && !isOverride)
iAttachments2.getLines().add();
iAttachments2.getLines().setCurrentLine(0);////////////////////////////////
iAttachments2.getLines().setFileExtension(extension);
iAttachments2.getLines().setFileName(baseName);
iAttachments2.getLines().setOverride(Integer.valueOf(1));
iAttachments2.getLines().setSourcePath(parentPath);
if (isAnexoEmpty) {
int add = iAttachments2.add();
int update = iAttachments2.update();
if (add != 0) {
log.error(sociedad.getLastErrorDescription());
if (sociedad.isInTransaction().booleanValue())
sociedad.endTransaction(SBOCOMConstants.BoWfTransOpt_wf_Commit);
return false;
}
int newKey = Integer.parseInt(sociedad.getNewObjectKey());
documents.setAttachmentEntry(Integer.valueOf(newKey));
int i = documents.update();
if (i != 0) {
log.error(sociedad.getLastErrorDescription());
if (sociedad.isInTransaction().booleanValue())
sociedad.endTransaction(SBOCOMConstants.BoWfTransOpt_wf_Commit);
return false;
}
if (sociedad.isInTransaction().booleanValue())
sociedad.endTransaction(SBOCOMConstants.BoWfTransOpt_wf_Commit);
return true;
}
int update = iAttachments2.update();
if (update != 0) {
log.error(sociedad.getLastErrorDescription());
if (sociedad.isInTransaction().booleanValue())
sociedad.endTransaction(SBOCOMConstants.BoWfTransOpt_wf_Commit);
return false;
}
if (sociedad.isInTransaction().booleanValue())
sociedad.endTransaction(SBOCOMConstants.BoWfTransOpt_wf_Commit);
return true;
}