Combine Values into One Field¶
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.
Sometimes metadata is entered through CSV, XML, or by other methods that might have values you want to be in one field separated out into multiple fields. Below is an example of how to accomplish this using the Modify Your Metadata activity.
Our example below will show how you can take a FirstName and LastName field and combine them into a field called FullName.
Full Script¶
batch.Documents.forEach(function (doc) {
var firstNameValue = doc.Metadata["Index"]["FirstName"] != null ? doc.Metadata["Index"]["FirstName"] : "";
var lastNameValue = doc.Metadata["Index"]["LastName"] != null ? doc.Metadata["Index"]["LastName"] : "";
var fullNameValue = firstNameValue + " " + lastNameValue;
builder.SetDocumentMetadata(doc.DocumentId, "Index", "FullName", fullNameValue);
});
Walkthrough¶
- First, we will cycle through the documents and grab the FirstName and LastName field values, so long as they're not null and populate the variables firstNameValue and lastNameValue respectively with the found values.
batch.Documents.forEach(function (doc) {
var firstNameValue = doc.Metadata["Index"]["FirstName"] != null ? doc.Metadata["Index"]["FirstName"] : "";
var lastNameValue = doc.Metadata["Index"]["LastName"] != null ? doc.Metadata["Index"]["LastName"] : "";
-
We will then build fullNameValue by concatenating firstNameValue and lastNameValue into a single field value.
-
Lastly, we will populate the metadata field FullName in the Index category of metadata on each of our documents with the value created as fullNameValue.