Description
In many instances, we've seen users need to separate a single piece of metadata into multiple fields. This can be first and last name, an invoice number from a prefix or suffix, or various other cases.
Below is an example of how we might separate out a value gathered by a barcode, called PageBarcode in this example by using a hyphen as a delimiter of the two values.
NOTE: Modify your Metadata is only available in Capture Server Pro 1.10 and later.
Example
var pattern = /\S{3}-\S{5}/
batch.Documents.forEach(function (doc) {
var barcodeValue = doc.Metadata["Index"]["PageBarcode"];
var valid = pattern.test(barcodeValue);
if (valid) {
var delimiterPosition = barcodeValue.indexOf("-");
var branchCodeValue = barcodeValue.substring(0, delimiterPosition);
var documentNumberValue = barcodeValue.substring(delimiterPosition + 1);
builder.SetDocumentMetadata(doc.DocumentId, "Index", "BranchCode", branchCodeValue);
builder.SetDocumentMetadata(doc.DocumentId, "Index", "DocumentNumber", documentNumberValue);
}
});
In this example, we will take a barcode value that is set with a branch code before a hyphen that is 3 characters and a document number that is 5 characters after the hyphen and set them to two pieces of metadata inside each document.
1. |
var pattern = /\S{3}-\S{5}/ |
|
First, we will use var pattern = /\S{3}-\S{5}/ to set the regular expression we will use to validate these barcodes are in the correct format. |
2. |
batch.Documents.forEach(function (doc) { |
|
Second, we will loop through each document using a ForEach to determine if the value PageBarcode is equal to our pattern set in step 1. |
3. |
var delimiterPosition = barcodeValue.indexOf("-"); |
|
Then, if the pattern validates, we will set the characters before the hyphen to a value called branchCodeValue and after the hyphen to documentNumberValue. |
4. |
builder.SetDocumentMetadata(doc.DocumentId, "Index", "BranchCode", branchCodeValue); |
|
Now that we have our variables set for each document, we can set the BranchCode and DocumentNumber fields in each document to these variables. |
Comments
0 comments
Please sign in to leave a comment.