You can use the Connect REST API to obtain the exact count of items in each job from Workflow. Let’s say your process has two branches, each calling a different job preset. After the Job Creation task is run in a branch, you can use a script that reads the JobID from the metadata and uses it to query the server for its contents.
The following script does this, storing the number of items for the job in JobInfo[9]. Note that it uses the default username/password for accessing the Connect server, you must change that to reflect your own settings. The code may appear complex at first, but once you realize most of it is for the btoa() utility method, which is only required for authentication purposes, then it becomes much less daunting.
var baseURL = "http://localhost:9340";
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
var uN = "ol-admin";
var uP = "secret";
var authToken = getToken(uN, uP);
var jobID = Watch.ExpandString("GetMeta(_vger_job_id[0], 10, Job.Group[0])");
var response = jsonGetRequest("/rest/serverengine/entity/jobs/"+jobID+"/contents",authToken);
if (response) {
var contentItems = JSON.parse(response);
Watch.Log("Items in job: " + contentItems.identifiers.length,2);
Watch.SetJobInfo(9,contentItems.identifiers.length);
}
/////////////////////////////
// Utility methods are below
/////////////////////////////
function jsonGetRequest(url, token){
var res=null;
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
xhr.open("GET", baseURL + url, false);
xhr.setRequestHeader("auth_token", token);
xhr.send();
if(xhr.status==200) {
res = xhr.responseText;
}
xhr = null;
return res;
}
function getToken(name, password){
var res=null;
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
var url = baseURL + "/rest/serverengine/authentication/login";
xhr.open("POST",url,false);
xhr.setRequestHeader("Authorization", "Basic " + btoa(name + ":" + password));
xhr.send();
if(xhr.status==200) {
res = xhr.responseText;
}
xhr = null;
return res;
}
function btoa(input) {
var TABLE = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
var REGEX_SPACE_CHARACTERS = /[\t\n\f\r ]/g;
input = String(input);
if (/[^\0-\xFF]/.test(input)) {
Watch.Log('String contains characters outside of the Latin1 range.',2);
}
var padding = input.length % 3;
var output = '';
var position = -1;
var a;
var b;
var c;
var d;
var buffer;
var length = input.length - padding;
while (++position < length) {
a = input.charCodeAt(position) << 16;
b = input.charCodeAt(++position) << 8;
c = input.charCodeAt(++position);
buffer = a + b + c;
output += (
TABLE.charAt(buffer >> 18 & 0x3F) +
TABLE.charAt(buffer >> 12 & 0x3F) +
TABLE.charAt(buffer >> 6 & 0x3F) +
TABLE.charAt(buffer & 0x3F)
);
}
if (padding == 2) {
a = input.charCodeAt(position) << 8;
b = input.charCodeAt(++position);
buffer = a + b;
output += (
TABLE.charAt(buffer >> 10) +
TABLE.charAt((buffer >> 4) & 0x3F) +
TABLE.charAt((buffer << 2) & 0x3F) +
'='
);
} else if (padding == 1) {
buffer = input.charCodeAt(position);
output += (
TABLE.charAt(buffer >> 2) +
TABLE.charAt((buffer << 4) & 0x3F) +
'=='
);
}
return output;
};