---
title: Using Folder Metadata in Activate with Custom Scripts and Expressions
slug: using-folder-metadata-in-activate-with-custom-scripts-and-expressions
createdAt: 2025-07-28T20:29:36.472Z
---

## Prerequisites

Before following this guide, ensure:

- Your environment has **Shared Folders configured**.
- These folders have been **synchronized into Activate** via the Folder Sync process.

## Using Custom Scripts to Read/Write Folder Metadata

### Sample Script

You can use a **Script-type parameter** in Activate Administrator to programmatically read and write metadata associated with folders. Here is a fully functional test script:

:::BlockQuote
using System;
using Innovation.Activate;
using Innovation.Activate.Resources;

class Script : ScriptBase
\{
&#x20;   public void main()
&#x20;   \{
&#x20;       var folderResource = Evaluator.GetObject(@"=//Resources/Folders/\\\MyFileShareScanTest\Test Folder 0001") as FolderResource;
&#x20;       if (folderResource is null) throw new Exception("Could not find folder");
&#x20;      &#x20;
&#x20;       LogAudit($"&#x7B;folderResource}");

&#x20;       var originalAllMetadata = folderResource.FolderMetaData;
&#x20;       LogAudit($"Original Metadata is:\r\n\{originalAllMetadata?.FormattedXml ?? "NULL"}");
&#x20;      &#x20;
&#x20;       var originalTestValue = Evaluator.GetString(folderResource, "=/FolderMetaData/testValue");
&#x20;       LogAudit($"Original Test Value is: &#x7B;originalTestValue}");
&#x20;       LogAudit($"");
&#x20;      &#x20;
&#x20;       XmlValue x = new XmlValue("folder");
&#x20;       x.SetValue("testValue", "My Test Value");
&#x20;       folderResource.WriteFolderMetaData(x);

&#x20;       var newAllMetadata = folderResource.FolderMetaData;
&#x20;       LogAudit($"New Metadata is:\r\n&#x7B;newAllMetadata.FormattedXml}");

&#x20;       var newTestValue = Evaluator.GetString(folderResource, "=/FolderMetaData/testValue");
&#x20;       LogAudit($"New Test Value is: &#x7B;newTestValue}");
&#x20;   }
}

:::

### What This Script Does

1. Finds a folder resource at a specific path inside Activate.
2. Logs the current metadata (if any).
3. Writes a new metadata element: \<testValue>My Test Value\</testValue>.
4. Logs the updated metadata.

Output Example

:::BlockQuote
Test Folder 0001
Original Metadata is:
NULL
Original Test Value is:&#x20;

New Metadata is:
\<?xml version="1.0" encoding="utf-16"?>
\<folder id="7456" path="\\\MyFileShareScanTest\Test Folder 0001" when="2025-05-22T04:37:51" site="\[None]" server="MyFileShareScanTest">
&#x20;   \<testValue>My Test Value\</testValue>
\</folder>
New Test Value is: My Test Value
\-----------------------------------------
Script Complete: 0.2 secs

:::

## Referencing Folder Metadata in Activate Expressions

### Activate Expression Syntax

Once metadata is written, you can access it in Activate using **XPath-style expressions** in conditions, parameters, or other scripts.

Example: Referencing the Metadata

:::BlockQuote
\=/FolderMetaData/testValue
:::

This will resolve to:

:::BlockQuote
My Test Value
:::

### Where You Can Use It

- **Parameters** – e.g., to auto-fill a field based on folder metadata
- **Form Logic** – e.g., hide/show elements conditionally
- **Scripts** – e.g., trigger actions or validations

### Tips

- Ensure the metadata node you reference exists to avoid null values.
- You can validate or view metadata structure directly using the Audit Log output in scripts.

## Summary

- Folder metadata enables powerful contextual workflows in Activate.
- You can read/write metadata using custom scripts.
- Use metadata values in Activate expressions with XPath syntax.

