10-16-2018 04:51 AM
I need to parse that XML to add metadata to the document via javascript. I just cannot find a way to extract the value from that XML. Any idea would be welcomed.
Thanks.
Pablo
10-17-2018 03:31 AM
From Repository JavaScript API, this should work:
var docXml = new XML(document.content);
10-17-2018 03:53 AM
Thanks Angel,
I got that far and it works but my problem is retrieving a value within the XML.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<DocumentSet>
<Document>
<FileName>Brief - Lettre_4umqrm82l5ay.pdf</FileName>
<FilePath>\\alfresco\alfresco\MailRoom\Brief - Lettre_4umqrm82l5ay.pdf</FilePath>
<Confidentiality>3-Organisation</Confidentiality>
<Departement>CUAC</Departement>
<Domein___Domaine>DC</Domein___Domaine>
<Info_type>Brief - Lettre</Info_type>
<Medewerker___Collaborateur>Alain Terrieur</Medewerker___Collaborateur>
<Status___Statut>5 - Overgedragen - Transféré</Status___Statut>
</Document></DocumentSet>
I just can't seem to get the <Info_type> Value!
Frustrating!
10-17-2018 05:36 AM
This should work:
docXml.DocumentSet.Document.Info_type
10-17-2018 06:09 AM
Angel, That is what I thought also but ... no luck!
This is taken to its most basic, following your advice and documentation!
var docXml = new XML(document.content);
var infoType = docXml.DocumentSet.Document.Info_type;
document.properties.title = infoType;
document.save();
Drowing in frustration!
Thanks for your help!
10-17-2018 08:59 AM
This works...
var docString = document.content;
if (docString.startsWith("<?xml")) {
docString = docString.split("\n").slice(1).join("\n")
}
var docXml = new XML(docString);
var infoType = docXml.DocumentSet.Document.Info_type;
logger.log(docXml.Document.Info_type);
... you can change / improve it, as it's a quick PoC.
10-17-2018 09:24 AM
Thanks Angel but I have no results. I even tried to change the name of the document but nothing. It is as if the variable was not populated.
I will give it a shot tomorrow on another Alfresco instance in the office and follow your proposition. I’ll let you know the results.
I really appreciate your time and help.
10-17-2018 09:45 AM
It looks like I included a bad sample.
IMO, the main problem is that you have to omit "DocumentSet" when recovering values from XML.
This doesn't work...
docXml.DocumentSet.Document.Info_type
... but this works
docXml.Document.Info_type
10-18-2018 12:51 AM
Thanks Angel, It works!
Big thanks for your help!
Explore our Alfresco products with the links below. Use labels to filter content by product module.