Barry,
I got this script from pre-sales, I think Phil wrote it. It retrieves the contentSet, loops through it, adding Page Count to the Document node.
Important notes:
- The ‘Execute Data Mapping’ Action should have the “Output records in Metadata” option set. This exposes the Connect database records as external (legacy) Metadata.
- You’ll run the script AFTER the ‘Create Print Content’ Action, as there is no content nor contentID until after this runs.
- Do NOT check the “Update Records from Metadata” in the ‘Create Print Content’ Action. For some reason this causes the script to return blank values for the page counts.
- Whatever field name you use in the script (I use ‘_vger_fld_pndPAGECOUNT’), should be in the Data Map (which in my case is a field named ‘pndPAGECOUNT’; Connect adds the “vger_fld” prefix). This isn’t strictly necessary. If you only need the Page Count inside of Workflow, you can bypass this. For my needs, I have other external Metadata Fields I add in a separate branch that I need for the Separation functionality within Connect’s Output Preset. In other words, I need to push my external (legacy) / Workflow Metadata back into Connect so the job and output presets can use it as INTERNAL Metadata.
- If you do need to push the legacy Metadata back into Connect content, use the ‘Update Data Records’ Action after the script executes.
- I added a “totalPages” local variable because I also needed a total page count, since “Pages in Group” is also defunct in Connect.
Note to OL R&D:
This split between internal/Connect Metadata and external/Workflow Metadata is maddening. I think if a script is required in order to get something as basic as “how many pages are in each document”, that is indicative of a missing standard plugin.
The ‘Create Print Content’ Action needs another option to “Update Metadata with Connect Content” or something as an option, and that option, when checked, should update the legacy Metadata Properties, such as “Pages in Document”.
It seems the “Retrieve items” Action should generate updated, correct Metadata, making the script obsolete, but I couldn’t get it to work. The Help Pages do not explain the Name value or how it relates to the ‘Set Property’ Action, and when I finally got it to run, the Metadata does not have accurate page count information.
Thomas Greer
var xhttp = new ActiveXObject(“Microsoft.XMLHTTP”);
var metaFile = new ActiveXObject(“MetadataLib.MetaFile”);
metaFile.LoadFromFile (Watch.GetMetadataFilename());
var metaJob = metaFile.Job();
var metaGroup = metaJob.Group(0);
var totalPages = 0;
var contentsetid = Watch.ExpandString(“GetMeta(_vger_contentset_id[0], 10, Job.Group[0])”);
var url = “http://localhost:9340/rest/serverengine/entity/contentsets/” + contentsetid + “/pages?detail=true”;
xhttp.open(‘GET’,url,false);
xhttp.setRequestHeader(‘Content-Type’, ‘application/json’);
xhttp.onreadystatechange = handlerGetDataRecord;
xhttp.send();
Watch.SetVariable(“totalPages”, totalPages);
function handlerGetDataRecord()
{
if (xhttp.readyState == 4) {
if (xhttp.status == 200) {
var contentsetPageDetails = JSON.parse(xhttp.responseText);
var contentsetPageDetailMap = {};
for (var idx=0; idx < contentsetPageDetails.length; idx++) {
contentsetPageDetailMap[‘’+contentsetPageDetails[idx].id] = contentsetPageDetails[idx].pages[0].count;
}
for (var idx=0; idx < metaGroup.Count; idx++) {
var contentItemId = metaGroup.Item(idx).FieldByName(‘_vger_contentitem_id’);
metaGroup.Item(idx).Fields.Add(‘_vger_fld_pndPAGECOUNT’, contentsetPageDetailMap[contentItemId]);
totalPages += contentsetPageDetailMap[contentItemId];
}
metaFile.SaveToFile (Watch.GetMetadataFilename());
}
}
}