Knowledge View Scripts

This section provides a reference for writing custom Knowledge View scripts for Process Director. The Knowledge View supports a custom script that can be called before the results are displayed to the user. The custom scripts are stored in the Process Director database in the Content List. The custom script is used to inspect, modify, calculate, or remove results from the Knowledge View.

To develop Knowledge View Scripts inside Visual Studio, use the fully functional Visual Studio project installed with the product named bpVS.zip. Refer to the sample file kview_script.ascx.

Writing a Knowledge View Script #

A Knowledge View can have a custom script that can alter the results of the displayed information.

When the Knowledge View runs, it will call this method in the script for EVERY row in the result:

public override bool KV_Display(List<NameValueEx> pColumns,
                                ContentObject pObject,
                                out bool pRemoveRow)

If you set the pRemoveRow to true, then the row being processed will be excluded from the report.

The example below will add the HTML “bold” tag around the value for the Amount columns.

<%@ Control Language="C#" AutoEventWireup="false"
    Inherits="BPLogix.WorkflowDirector.SDK.bpScript" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="BPLogix.WorkflowDirector.SDK" %>
<script runat="server">
    public override bool KV_Display(List<NameValueEx> pColumns,
                                    ContentObject pObject,
                                    out bool pRemoveRow)
    {
        pRemoveRow = false;// Do not remove the row being processed
        foreach (var entry in pColumns)
        {
            // Bold the Amount column
            if (entry.Name == "Amount")
            {
                entry.Value = "<b>" + entry.Value + "</b>";
            }
        }
        return true;// Return true if a value has changed
}
</script>

Notice that Knowledge View scripts inherit from  BPLogix.WorkflowDirector.SDK.bpScript.

This method will be called with the following environment:

LOCAL VARIABLE

DESCRIPTION

CurrentUser

Optional instance of the current User object

CurrentPartition

Instance of the current Partition object

bp

The bp environment

NameValueEx List Object #

The Knowledge View script uses the NameValueEx list object to store the values in each of the Knowledge View columns. The Value attribute of the NameValueEx list is always a string, but, of course, the value may be derived from a non-string object. Let's say that a value we wish to find comes from a checkbox. In that case, we would see the Value of the checkbox represented by the string values "True" or "False". If the Value contains a string representation of a number, on which you'd like to do some math, you can use the built-in Process Director conversion methods to convert the Value string to an appropriate numeric value.

In addition to the Value attribute, the NameValueEx list class also has a ValueEx attribute that contains the actual .NET DataItem object for the field.

The NameValueEx object constructor has four overloads:

//Null values
public NameValueEx()

//String Name and Value
public NameValueEx(string pName, string pValue)

//String Name and Value, and Decimal Number
public NameValueEx(string pName, string pValue, decimal pNumber)

//String name and Value, and List DataItem
public NameValueEx(string pName, string pValue, DataItem pDataItem)

When using the Value attribute for the value of a Knowledge View column, you should be aware that, when KView columns are displayed, there is often additional HTML code in the Value, to enable features like tooltips to work. This HTML is included in the Value attribute. For example, the Value attribute for a date column, like the Last Updated column, which is one of the default columns included in every new Knowledge View definition, will be:

<span ontouchstart='iShowTip("5/22/2025 10:26 AM", 170); event.stopPropagation();' onmouseover='iShowTip("5/22/2025 10:26 AM", 170)'ontouchend='iHideTip();' onmouseout='iHideTip();' >5/22/2025</span>

In this example, the date "5/22/2025" will appear as the text shown in the column, but the Value attribute will include all of the additional HTML shown here.

Sometimes, however, you need to return only the actual data value of the column. In that case, the ValueEx attribute will return only the data, without the additional HTML. This attribute is useful if you need to use the data value in a comparison. By using this attribute, we can create a script to display all dates after 5/15/2025 with yellow text on a red background:

<%@ Control Language="C#" AutoEventWireup="false"
    Inherits="BPLogix.WorkflowDirector.SDK.bpScript" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="BPLogix.WorkflowDirector.SDK" %>

<script runat="server">
public override bool KV_Display(List<NameValueEx> pColumns, ContentObject pObject)
{
    string bcolor = "red";
    string color = "yellow";
    DateTime dt = new DateTime(2025, 05, 15);
    int col_num = 0;

    foreach (var entry in pColumns)
    {
        if (entry.Name == "Last Updated")
        {
            if (entry.ValueEx.DateTime.Date > dt.Date)
                entry.Value = "<div style=\"color: " + color + "; background: " +
                    bcolor + ";\">" + entry.Value + "</div>";
        }
        col_num++;
    }
    return true;
}
</script>

In this example, we've created a DateTime Variable named "dt" to specify the date we want to compare, "5/15/2025". By using the ValueEx attribute and casting it to a date (entry.ValueEx.DateTime.Date) in the date comparison, we can evaluate the column's data value without having to worry about all the extra HTML that's included in the Value attribute.

But, notice that when we set the Value of the column for all of the rows that match our condition, we can simply add the additional HTML for the color and background color styles we want to apply, placing them outside of the Value attribute to ensure that we don't overwrite the existing HTML that Process Director has already inserted into the column. You should, of course, use caution when writing the Value attribute to avoid incorrectly replacing it.

So, we can use the ValueEx attribute to read the column's data, while using the Value attribute to cautiously write the column's desired HTML.