EventCtx()
function EventCtx(): {
RelPath: string;
RelTargetPath: string;
VFSName: string;
Username: string;
VirtualSite: string;
};Returns the entire event context as a single object. This is the same information exposed by the individual Ctx* helper functions, delivered in one call:
| Field | Equivalent helper | Meaning |
|---|---|---|
RelPath | CtxRelPath() | VFS-relative path of the file that caused the event; "" when no file applies |
RelTargetPath | CtxRelTargetPath() | VFS-relative target path of a rename or move; "" otherwise (added in v8.0.2) |
VFSName | CtxVFSName() | Name of the VFS the event refers to; "" for events that fire before VFS selection (added in v8.0.4) |
Username | CtxUsername() | Username of the user whose session triggered the event; "" for events that fire before authentication (added in v8.0.5) |
VirtualSite | CtxVirtualSite() | ID of the virtual site the event occurred in; never empty, for any event (added in v8.0.6) |
Like every Ctx* value, the whole object is captured at the moment the event fires and frozen into the script's execution context for its entire lifetime. It never changes while the script runs, regardless of what the client does in the background, so it is always safe to read at any point during execution.
TIP
EventCtx() is also forward compatible: when future versions of Syncplify Server! enrich the event context with new information, the new fields will appear in this object automatically. If you want your scripts to take advantage of upcoming context fields as soon as they ship, read them from EventCtx(). The Username field added in v8.0.5, and the VirtualSite field added in v8.0.6, are exactly this promise being kept: scripts that were already reading EventCtx() saw them appear with no code changes.
Example
{
var ctx = EventCtx();
Log("Event: " + EventHandler());
Log("File path: " + ctx.RelPath);
Log("Target path: " + ctx.RelTargetPath);
Log("VFS name: " + ctx.VFSName);
Log("Username: " + ctx.Username);
Log("Virtual site: " + ctx.VirtualSite);
if (ctx.VFSName === "Quarantine" && ctx.RelPath !== "") {
Log("File activity on the quarantine VFS by " + ctx.Username + ": " + ctx.RelPath);
}
}WARNING
EventCtx() is not available prior to v8.0.4. Please upgrade to v8.0.4 or newer to use this function. Its Username field is not available prior to v8.0.5, and its VirtualSite field is not available prior to v8.0.6; both read as undefined on versions older than the one that introduced them.
See also
CtxRelPath(): the path of the file that triggered the eventCtxRelTargetPath(): the target path of a rename or move operationCtxVFSName(): the name of the VFS the event refers toCtxUsername(): the username of the user whose session triggered the eventCtxVirtualSite(): the ID of the virtual site the event occurred inEventHandler(): returns the name of the event that triggered this script
