1 var REST = library.REST.REST();
  2 var myData = {};
  3 var myFieldId = [];
  4 
  5 /**
  6  * Adds an object to myData containing the value of the given schema/field
  7  * @param theAssetId - the id of the asset to get the value of
  8  */
  9 function getField(theAssetId) {
 10   var aFile = fileManager.getFileObjectById(theAssetId);
 11   if (aFile == null) {
 12     try {
 13       aFile = new ManagedFile(theAssetId);
 14     } catch (anEr) {
 15       REST.submitError(theAssetId, "The file does not exist");
 16     }
 17     if (aFile == null) {
 18       REST.submitError(theAssetId, "The file does not exist");
 19       return;
 20     }
 21   }
 22   myData[theAssetId] = {};
 23   for (var i = 0; i < myFieldId.length; i++) {
 24     var mySplitSchemaField = myFieldId[i].split(" ");
 25     var aValue = aFile.xmp.meta.getField(
 26       new Property(mySplitSchemaField[0], mySplitSchemaField[1])
 27     );
 28     if (aValue != null) {
 29       aValue = aValue.toString();
 30     }
 31     myData[theAssetId][myFieldId[i]] = aValue;
 32   }
 33 }
 34 
 35 /**
 36  * Returns the value of a desired field for the given Asset IDs.
 37  * @description Gets the value of a desired 'field' contained in a specified 'schema' for the assets given by AssetID in 'src'. These values are parsed into a text object keyed by AssetID from the JSON file in which they are contained, and by default are displayed to the user.
 38  * @example 'MBurl'/wf/restapi/1/getField?src=["Asset ID"]&fieldId='TheFieldId'
 39  * @example <a target="_blank" href='http://127.0.0.1:55555/wf/restapi/1/getField?src=["12345"]&fieldId=["http://brightech.com/ns/mb date_entered"]'>http://127.0.0.1:55555/wf/restapi/1/getField?src=["12345"]&fieldId=["http://brightech.com/ns/mb date_entered"]</a>
 40  * @class Returns the value of a desired field for the given Asset IDs.
 41  * @name GetField
 42  * @param src AssetID/list or file path to get the XMP field values from.
 43  * @param savedSelection the saved selection id to iterate over.
 44  * @param fieldId ex http://purl.org/dc/elements/1.1/ subject
 45  * @returns ( {'AssetID': "value",...} )
 46  */
 47 function main() {
 48   myFieldId = REST.toArray(REST.getParameter("fieldId", true));
 49   var aParamValues = REST.getParametersToIterate(["src", "savedSelection"]);
 50   if (myData.error != null) {
 51     return REST.formatResponse();
 52   }
 53   REST.iterateThroughParameters(aParamValues, getField);
 54   return REST.formatResponse();
 55 }
 56 main();
 57