Using JavaScript, is there a way to get the version of the document being edited when you have a topic open in Create? We have code that requires the topic version.
Using JavaScript, is there a way to get the version of the document being edited when you have a topic open in Create? We have code that requires the topic version.
Yes, this should be possible. The document contains a processing-instruction with this information. You can retrieve this for example in the following way:
function getVersion(doc) { if (!doc) return false; var ish = doc.selectSingleNode("processing-instruction('ish')"); if (!ish) return false; var result = ish.getTextContent().match("version=\"(.*?)\""); if (!result || result.length < 2) return false; return result[1]; } getVersion(Editor.getActiveDocument());
Yeah, the sample code you sent returns false and the raw xml returned by getXML() shows that the doctype deceleration is immediately followed by the concept tag. I would expect to see the ish PI between them. Im on Create 5.2.4 and Architect 11.0.2929.3.
Ok, that explains it, above snippet only works in 5.3/12.0.
Then still it should be possible, but using a different approach:
var activeDocument = SDL.Models.getItem(window.location.hash.substring(1)); SDL.Utils.Xml.getInnerText(activeDocument.getWrappedObject().getXmlDocument(), "/data/item/@version");
This still works in 2016, however it looks like the case of the attribute names on the data tag was switched from camel case to all lowercase.
This still works in 2016, however it looks like the case of the attribute names on the data tag was switched from camel case to all lowercase.