# Adding a new Column

This is an example of a [script add-in](../script_add-ins) that adds a new information column to Opus.

This column, **Is Modified?**, indicates whether a file has been modified since it was created. This is performed by simply comparing whether the item's creation and modification dates are the same.

* For files that have been modified, the column displays _Yes_, and for files that haven't been modified it displays _No_. Nothing is displayed for folders.
* When sorting by this column, modified files are displayed above non-modified files.
* When grouping by this column, the two groups are labeled _Modified_ and _Never Modified_.

The basic procedure to add a custom column from a [script add-in](../script_add-ins) is:

* Either:
  * In the [**OnInit**](../../reference/scripting_reference/scripting_events/oninit) event, create a \*\*[ScriptColumn](../../reference/scripting_reference/scripting_objects/scriptcolumn)\*\*object with the [**ScriptInitData**](../../reference/scripting_reference/scripting_objects/scriptinitdata)**.AddColumn** method.
  * Or, in the [**OnAddColumns**](../../reference/scripting_reference/scripting_events/onaddcolumns) event, create a \*\*[ScriptColumn](../../reference/scripting_reference/scripting_objects/scriptcolumn)\*\*object with the [**AddColData**](../../reference/scripting_reference/scripting_objects/addcoldata)**.AddColumn** method.
*   Initialize the properties of the \*\*[ScriptColumn\*\*](../../reference/scripting_reference/scripting_objects/scriptcolumn)\*\*object. At a minimum you must populate the **name** and **method** properties. \* Create a separate function in your script-add in, with the **method** name you specified for the column. This method will be called when Opus wants to retrieve data for your column.

    // Set the script type to JScript to use this script // The OnInit function is called by Directory Opus to initialize the script add-in function OnInit(initData) { // Provide basic information about the script by initializing the properties of the ScriptInitData object initData.name = "Is Modified Column"; initData.desc = "Adds a column that indicates if a file has ever been modified."; initData.copyright = "(c) 2014 Jonathan Potter"; initData.default\_enable = true; // Create a new ScriptColumn object and initialize it to add the column to Opus var cmd = initData.AddColumn(); cmd.name = "IsModified"; cmd.method = "OnIsModified"; cmd.label = "Is Modified?"; cmd.autogroup = false; // we provide our own grouping information cmd.autorefresh = true; // refresh column when files change cmd.justify = "center"; cmd.match.push\_back("Yes"); // when searching, these are the only two options cmd.match.push\_back("No"); }

    // Implement the IsModified column (this entry point is an OnScriptColumn event). // The name of this function must correspond to the value specified for the \*\*method \*\*property when the column was added in OnInit function OnIsModified(scriptColData) { // scriptColData is a ScriptColumnData object. // First check that this is the right column (it should be since we only added one). if (scriptColData.col != "IsModified") return; // We don't provide a value for folders since their timestamps don't mean much. // We set the sort key to 3 so they come last (in case the user is mixing files and folders). if (scriptColData.item.is\_dir) { scriptColData.value = ""; scriptColData.sort = 3; } // For files, are the two dates the same? else if (new Date(scriptColData.item.create).valueOf() == new Date(scriptColData.item.modify).valueOf()) { scriptColData.value = "No"; scriptColData.group = "Never Modified"; scriptColData.sort = 2; } // the dates are different, therefore modified else { scriptColData.value = "Yes"; scriptColData.group = "Modified"; scriptColData.sort = 1; } }
