Hi all,
I am trying to use the transformDocument function to convert a text file into a pdf file.
I have a custom content type (text file) with a custom action - this action calls the custom web script to convert to pdf.
For one time transformation , it works fine. However, if I modify content in the same file then try to convert this into pdf, it raises the duplicate name error.
In the custom webscript file:
var nodeRef = utils.getNodeFromString(args["nodeRef"]);
var newPdf = nodeRef.transformDocument("application/pdf");
model.pdfNodeRef = newPdf;
I tried exception handlings to catch this error.
I also tried to add the version name to newPdf node.
Could anyone give me some suggestions please?
Please note that I am working on Alfresco 5.1.1
Thank you
Hi MJ,
you get this error because there is already a pdf with the same name. It won't be replaced automatically - so you have to remove the pdf version of your document before creating a new one.
var node = utils.getNodeFromString(args["nodeRef"]);
var pdfName=node.name.replace(/\.+?$/,".pdf"); //Replace the extenison of node.name with ".pdf"
var pdfNode=node.parent.childByNamePath(pdfName);
if (pdfNode !== null) { pdfNode.remove()}; //if pdf is existing, delete it
var newPdf = node.transformDocument("application/pdf");
model.pdfNodeRef = newPdf;
Not tested - hope it works,
Martin
Thank you Martin,
I've tried your code and it came up with two errors.
There was an error "Ambiguous calling to String.replace function" so i used (node.name+ "") instead.
Another issue I am having trouble is that now the code cannot find the node info. The log shows 'Node does not exist' even for the first conversion of pdf documnet. I think the 'node.parent.childByNamePath' is the one which causes this issue.
Could give me an advice please?
Thank you
Hi MJ,
(node.name+"") is right, and the second problem is just because the line to build the pdf name seems not to work:
var pdfName=node.name.replace(/\.+?$/,".pdf");
replace it with
var pdfName=(node.name+"").substr(0,name.lastIndexOf("."))+".pdf";
should work now. :-)
Thank you for your support Martin,
I still see the following SAME error when I try to create another pdf document of the same txt file:
Caused by: org.springframework.dao.DuplicateKeyException:
### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegr
ityConstraintViolationException: Duplicate entry '4186-33-2255312862-self manage
ment.pdf' for key 'parent_node_id'
### The error may involve alfresco.node.update_ChildAssocUniqueName-Inline
### The error occurred while setting parameters
### SQL: update alf_child_assoc set child_node_name_crc = ?,
child_node_name = ? where id = ?
### Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationExce
ption: Duplicate entry '4186-33-2255312862-self management.pdf' for key 'parent_
node_id'
; SQL []; Duplicate entry '4186-33-2255312862-self management.pdf' for key 'pare
nt_node_id'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityC
onstraintViolationException: Duplicate entry '4186-33-2255312862-self management
.pdf' for key 'parent_node_id'
Maybe the these lines are not executed properly before the transformDocument function
var pdfNode=node.parent.childByNamePath(pdfName);
if (pdfNode !== null) { pdfNode.remove()}; //if pdf is existing, delete it
Or it might be due to the custom associations I use in the original text file?
Thank you
MJ
I...yes, this is not a simple "duplicate name" errror. The error is caused by some property value or logic in the context of an (your) association.
Thank you Martin,
I am using two custom content types. I call them 'A' and 'B' here.
The content type 'A' is the text type that has the action to convert to the pdf file.
The content type 'B' is also the text type.
The 'A' has child association to content type 'B'.
I might remove the child association in 'A' and give a try. Thank you
- MJ
Ask for and offer help to other Alfresco Content Services Users and members of the Alfresco team.
Related links:
By using this site, you are agreeing to allow us to collect and use cookies as outlined in Alfresco’s Cookie Statement and Terms of Use (and you have a legitimate interest in Alfresco and our products, authorizing us to contact you in such methods). If you are not ok with these terms, please do not use this website.