How to write custom TLEs per page with Workflow?

Hi!

I’m trying to write TLEs to an AFP output with PReS Workflow. Wrinting in the Documents is working in my script below, but I’d like to include page numbers for every page.
I assume, there is a way to do this, as per Document, custom metadata can be made.

Here’s my script, with the currently not working part highlighted as “NOT WORKING”.

SCRIPT--------------------------------------------------------------------------

var xhttp = new ActiveXObject(“MSXML2.ServerXMLHTTP”);
var metaFile = new ActiveXObject(“MetadataLib.MetaFile”);
metaFile.LoadFromFile (Watch.GetMetadataFilename());
var metaJob = metaFile.Job();
var metaGroup = metaJob.Group(0);
var totalPages = 0;
var totalDocs = 0;

var fso = new ActiveXObject(“Scripting.FileSystemObject”);

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, ‘ol-admin’, ‘1234’);
xhttp.setRequestHeader(‘Content-Type’, ‘application/json’);
xhttp.onreadystatechange = handlerGetDataRecord;
xhttp.send();

Watch.SetVariable(“global.totalPages”, totalPages);
Watch.SetVariable(“global.totalDocs”, totalDocs);

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.length;
totalDocs++;
fh1.WriteLine(contentsetPageDetailMap[‘’+contentsetPageDetails[idx].id]);
}

      for (var idx=0; idx &lt; metaGroup.Count; idx++)
      {
        var contentItemId =  metaGroup.Item(idx).FieldByName('_vger_contentitem_id');
        var metaGroupDoc = metaGroup.Item(idx);

        metaGroup.Item(idx).Fields.Add('_vger_fld_pndPAGECOUNT', contentsetPageDetailMap[contentItemId]);

        metaGroup.Item(idx).Fields.Add('_vger_fld_pndDOCNUMBER', idx+1);
        metaGroup.Item(idx).Fields.Add('_vger_fld_pndDOCCOUNT', totalDocs);
        metaGroup.Item(idx).Fields.Add('_vger_fld_pndPAGECOUNT', contentsetPageDetails[idx].pages.length);

        for (var pageNumber=0; pageNumber&lt;contentsetPageDetails[idx].pages.length; pageNumber++)
        {
          // __THIS PART IS NOT WORKING__ //
          metaGroup.Item(idx).Item(0).Fields.Add('_vger_fld_pndPAGENUMBER', pageNumber+1);
        }

        totalPages += contentsetPageDetailMap[contentItemId];
      }

      metaFile.SaveToFile (Watch.GetMetadataFilename());

}

}
}

Not sure of how all of this is setup but it seems you are trying to add a metadata field that doesn’t already exist.

If your “_vger_fld_pndPAGENUMBER’” doesn’t already exist as part of your Datamodel, then it will not work. You will get error between your Datamapper and CreatePrint Context.

If this is the case, simply add it as a ‘javascript’ field in your Datamodel and update it in your script.