Description
You can perform conditional metadata manipulation using If Else statements. Below is a simple example of this being used to set whether a document has been indexed.
NOTE: Modify your Metadata is only available in Capture Server Pro 1.10 and later.
Example
var fieldToSet = "IsIndexed"; // Field name you want to set
var valueToSet = true; // Value you want to set if fieldToCheck not null or white
batch.Documents.forEach(function (doc)
{
var fieldToCheck = doc.Metadata["Index"]["IndexUser"]; // Change here to pick the field we are looking at
if (!(fieldToCheck == null || fieldToCheck.trim() === ''))
{
builder.SetDocumentMetadata(doc.DocumentId, "Index", fieldToSet, valueToSet);
}
else
{
builder.SetDocumentMetadata(doc.DocumentId, "Index", fieldToSet, false);
}
});
This script is more specifically checking the IndexUser field for a value. This is set when a user manually indexes a document in Upload, Scan, or Index. If a value is present, we are going to set a value of IsIndexed to true.
1. |
var fieldToSet = "InvNum"; |
|
First, we want to create our variables. In this example we will have our field we want to set, fieldToSet, and the value we want to set it to, valueToSet. fieldToSet will be set to IsIndexed for this example, and our value will either be true or false, but we will default it to true for now. |
2. |
batch.Documents.forEach(function (doc) |
|
Then, we will use a forEach to cycle through each document to perform our task on all documents. |
3. |
var fieldToCheck = doc.Metadata["Index"]["IndexUser"]; |
|
From there, you will set a new variable called fieldToCheck to the metadata we want to look at. In this case it will be the IndexUser field.
|
4. |
if (!(fieldToCheck == null || fieldToCheck.trim() === '')) |
|
Now we'll check to see if the field is not null and trim any trailing spaces. |
5. |
builder.SetDocumentMetadata(doc.DocumentId, "Index", fieldToSet, valueToSet); |
|
If the If statement is met, which means the value is not null, we will set fieldToSet, IsIndexed, to valueToSet which is currently set to true, per step 1. Otherwise, we set fieldToSet to false. |
When using this step, you should now see a field called IsIndexed in the monitor on a document and it will be set to true or false based on whether the IndexUser field is empty.
Comments
0 comments
Please sign in to leave a comment.