I'm after getting the OpenText Content Server node id using a word macro after a Content Server user creates a word doc by opening word on their pc and saves (using the enterprise connect dialog) and before the word doc is closed - I'm building a macro to hook the item number and pull some metadata into the doc, allowing the user to insert/update a document footer.
Is there some aspect of the various APIs or SDKs that will allow a word macro to access its own node id (and possibly other metadata) in this scenario?
I've found the file C:\Users[username]\AppData\Roaming\OpenText\OTEdit\sync.fedb which seems to hold a mapping between the file location/name and the document in content server, but interrogating this directly seems like a bit of a hack as OTEdit.exe always has a lock on the file, and I wonder if there is a supported way to do this.
I've investigated DPS as a way to stamp the content server node id into the word doc properties, and while this works if the user closes and re-opens the doc, the properties are not available before the doc is closed and so it is not useful in this situation.
I found a different approach because sync.fedb
is locked by the OTEdit
process, and there doesn't seem to be any way to access the document metadata via the SDK using a word macro. It's a bit of a hack, but I've put the details here in case anyone else is interested in doing this.
Edited documents are stored under a folder in a path like: C:\Users\[username]\AppData\Roaming\OpenText\OTEdit\EC_[servername]\[folder]\[current document name]
[folder]
might match a folder in Content Server, or might not - it is better to check the ~otdirinfo.ini
file and parse the parent folder id out of the Browse
url.
From here we can do a database search using something like:
SELECT
t.DataID AS NodeId,
CAST(t.CreateDate AS DATE) AS CreateDate,
CASE WHEN k.FirstName IS NULL
AND k.LastName IS NULL THEN k.Name
ELSE LTRIM(RTRIM(( ISNULL(k.FirstName, '') + ' ' + ISNULL(k.LastName, '') )))
END AS CreatedByFullName,
CASE WHEN kr.FirstName IS NULL
AND kr.LastName IS NULL THEN kr.Name
ELSE LTRIM(RTRIM(( ISNULL(kr.FirstName, '') + ' ' + ISNULL(kr.LastName, '') )))
END AS ReservedByFullName,
t.CreatedBy,
t.ReservedBy,
t.ParentID,
t.Name AS Title,
v.FileName
FROM
DTree t
INNER JOIN KUAF k
ON t.CreatedBy = k.ID
LEFT OUTER JOIN KUAF kr
ON t.ReservedBy = kr.ID
INNER JOIN DVersData v
ON t.DataID = v.DocID AND t.VersionNum = v.Version
In practice, I have written an API to wrap the database lookup that returns the results of interest in JSON, which is slightly easier deal with than managing database connections and returns results faster than CWS at my site. I use the handy VBA-Web macros to make the call and handle parsing, place the results of the call into the word doc properties, and then call our existing footer-generation macro.
Note: I'm using Content Server 10.5 for this, apparently the approach for extracting parent id sometimes differs per version.