Skip to content

Basic Approval Automation

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.

KnowledgeLake deals with a lot of transactional content, and in turn, a lot of transaction-related activities such as approvals. Below is an example of a simple approval automation to get you started using the Modify Your Metadata activity.

For each document in a batch, we are going to get the value for the BalanceDue field and convert it to a float data type. If the BalanceDue value is less than or equal to zero, the IsApproved field is set to true. Otherwise, the IsApproved field is set to false.

Full Script

batch.Documents.forEach(function (doc) {
    var balanceDueValue = parseFloat(doc.Metadata["Index"]["BalanceDue"]);

    if (balanceDueValue <= 0) {
        builder.SetDocumentMetadata(doc.DocumentId, "Index", "IsApproved", "true");
    }
    else {
        builder.SetDocumentMetadata(doc.DocumentId, "Index", "IsApproved", "false");
    }
});

Walkthrough

  1. First, you will want to cycle through each document and get the value of the BalanceDue field and convert it to a float called balanceDueValue.
batch.Documents.forEach(function (doc) {
    var balanceDueValue = parseFloat(doc.Metadata["Index"]["BalanceDue"]);
  1. Second and thirdly, we will want to look at the value and determine if there is in fact a balance due. If there is a balance of 0, there is no balance and the IsApproved field will be set to true.
        if (balanceDueValue <= 0) {
            builder.SetDocumentMetadata(doc.DocumentId, "Index", "IsApproved", "true");
        }
    
  2. If the value is not less than or equal to zero, the IsApproved field will be set to false.
    else {
            builder.SetDocumentMetadata(doc.DocumentId, "Index", "IsApproved", "false");
        }