Skip to content

Replace Values in Table Cells

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.

This example shows how to look for a certain character in a column's data and replace it with another. In this case, look for any S characters and replace them with $ characters. Before it does the replace, this code also checks to see if the S precedes a valid currency format.

var workingTable = builder.ConvertTableFieldToTableArray(batch.Documents[0].Metadata['Index']['TableField']);
var targetColumnIndex = 3;
//check that there are that many columns
if (workingTable[0].length > targetColumnIndex) {
    for (var i = 0; i < workingTable.length; i++) {
        //Checks to see if the field is a currency value proceeded by an S
        if (workingTable[i][targetColumnIndex].match(/S((\s*[1-9]\d{0,2}(,\d{3})*)|0)(\.\d+)?\s*$/gm) != null) {
            workingTable[i][targetColumnIndex] = workingTable[i][targetColumnIndex].replace("S", "$");
        }
    }
    builder.SetDocumentMetadata(batch.Documents[0].DocumentId, 'Index', 'TableField', builder.ConvertTableArrayToTableField(workingTable));
}