OL Learn

How to get all the document level metadata field names

Hi,

I am trying to get the metadata field names of the first document in the first group of my metadata file. I am using the below script but all it returns is one field name: _vger_record_id

var myMeta = new ActiveXObject(“MetadataLib.MetaFile”);
myMeta.LoadFromFile(Watch.GetMetadataFileName());
var myGroup = myJob.Group(0);
var myDoc = new Enumerator(myGroup).item();
var fieldcount = myDoc.Count;
Watch.Log('fieldcount: ’ + fieldcount,2);
for(var x = 0; x < fieldcount; x++){
Watch.Log('Field ’ + x + ': ’ + myDoc.fields.Name(x),2);
}

Can anyone help please?

I think you overcomplicated things a little. Try with this:

var myMeta = new ActiveXObject('MetadataLib.MetaFile');
myMeta.LoadFromFile(Watch.GetMetadataFileName());
var myFields = myMeta.Job().Group(0).Document(0).Fields;
var fieldCount = myFields.Count;
for(var x = 0; x < fieldCount; x++){
  Watch.Log('Field ' + x + ': ' + myFields.Name(x) + ' --- Value: ' + myFields.Item(x),2);
}
1 Like

Sublime! It works perfectly :slight_smile:

I think I was too quick :-)…
I am having some issues selecting the correct group because just before this script there is a metadata filter which filters the metadata base on the number of pages in the group.

This script seems to get the first metadata document in the original metadata file but not in the filtered one, yielding incorrect result.

Is there a way to get the first document within the new filtered metadata structure as the index will not always be 0 in this case?

The process does the following:
Filter metadata
Split metadata on Group level
Then run this script to get all field names and values in a json which I will send to a third party app. So it’s dynamic.

Getting the value of the filtered metadata document filed with
Watch.ExpandString(“GetMeta(” + myFields.Name(x)+ “[0], 10, Job.Group[0].Document[0])”);

seems to work now.
Am I doing it correctly or there an issue in obtaing the values these way in this case?

Yep, that’s the proper way of doing it: by splitting on metadata, you are essentially creating metadata chunks, and on each iteration, the fields you are looking for are on Document[0] of that chunk.

1 Like