Conditionally Set a Field Value¶
Legacy (Process Designer)
This page describes a script for the Modify Your Metadata activity of Process Designer. It was replaced by the Custom Step in Workflow. The script may not run as a Custom Step without changes. For new work, use the Custom Step reference.
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 using the Modify Your Metadata activity.
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.
Full Script¶
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);
}
});
Walkthrough¶
- 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.
fieldToSetwill 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.
-
Then, we will use a forEach to cycle through each document to perform our task on all documents.
-
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.
-
Now we'll check to see if the field is not null and trim any trailing spaces.
-
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.