Skip to content

Smart View Perspectives from Content Script

Overview

Module Suite 4.1.0 (Polaris) lets a Content Script create, read, update, enable, and disable Smart View perspectives through the amsui (Smart UI) service. You no longer need the Perspective Manager to set up a landing page, a container perspective, or a workspace perspective. A script can build the same definition, and you can keep that script under version control, run it again on another environment, and create many perspectives in one call.

The API is a set of fluent builders. Each setter returns the builder, so calls chain. Nothing reaches Content Server until you call a save method.

Service name

The service is available in scripts as amsui. All factories on this page (newPerspectiveRequest(), newFlowLayout(), newNodesTableWidget(), and so on) are methods of amsui.

General Concepts

A perspective has four parts:

  • Request: a CSPerspectiveRequest holds the title, the perspective type, the scope, the layout, and optional rules.
  • Layout: a CSPerspectiveLayout decides how widgets are arranged, for example a flow of tiles or three named zones.
  • Widgets: each CSPerspectiveWidget is one Smart View widget or Module Suite tile, with its own options.
  • Rules: optional CSPerspectiveRule conditions make the perspective rule-based.

When you save the request, Content Server stores the perspective as a node, by default in the Perspectives Volume. Reading it back returns a CSPerspective read model, which you can turn into a new request for an update.

flowchart LR
    amsui["amsui service"] --> request["CSPerspectiveRequest<br/>title, type, scope"]
    amsui --> layout["CSPerspectiveLayout<br/>flow, left-center-right, ..."]
    amsui --> widgets["CSPerspectiveWidget<br/>typed or generic"]
    amsui --> rules["CSPerspectiveRule<br/>optional conditions"]
    widgets --> layout
    layout --> request
    rules --> request
    request -->|"createPerspective / updatePerspective / saveAllPerspectives"| saved["Perspective node<br/>Perspectives Volume"]
    saved -->|"getPerspective / getPerspectives"| readModel["CSPerspective<br/>read model"]
    readModel -->|"toRequest()"| request

Enumerations for perspective types, scopes, layout types, widget kinds, and option values live in SmartViewEnums. Its package is a default script import, so you can write SmartViewEnums.LayoutType.FLOW without an import. Every method that takes an enum also has a String overload that takes the raw value.

Building and Saving a Perspective

Service methods

Method Description Since
newPerspectiveRequest() Creates a new, empty CSPerspectiveRequest bound to the service 4.1.0
createPerspective(request) Creates a perspective. Returns the CSNode of the new perspective, looked up on a best-effort basis (see the note below) 4.1.0
updatePerspective(perspective, request) Updates the existing perspective node perspective with the state in request. Returns the refreshed CSNode 4.1.0
updatePerspective(perspectiveId, request) Same as above, with the perspective DataID 4.1.0
saveAllPerspectives(requests) Creates and/or updates up to 10 perspectives in one atomic call. Returns true on success 4.1.0
enablePerspective(perspective) / enablePerspective(perspectiveId) Enables a perspective 4.1.0
disablePerspective(perspective) / disablePerspective(perspectiveId) Disables a perspective 4.1.0
getPerspectives(node) Lists the perspectives associated with a node (local overrides configured for that container). Returns an empty list when there are none 4.1.0
getPerspective(perspective) / getPerspective(perspectiveId) Loads one perspective definition from its perspective node 4.1.0

All save, enable, and disable methods throw ExecutionFaultException when Content Server rejects the call. The save methods throw InvalidParamException when a request is incomplete.

Best-effort result of createPerspective

Content Server does not return the new node id. createPerspective looks the node up by title, under the parent() container if you set one, otherwise under Perspectives. The result can be null even though the save succeeded, for example when the title is ambiguous or Content Server made it unique. Use unique titles, or read the perspective back with getPerspectives(node) for local perspectives.

Enable and disable are strict

enablePerspective fails when the perspective is already enabled, and disablePerspective fails when it is already disabled. Both fail when the user cannot edit the perspective.

Request builder

CSPerspectiveRequest describes one perspective. A request needs a title, a type, and a layout. A local request also needs a target node.

Method Description Since
title(title) Sets the perspective title, used as the node name. Required 4.1.0
type(overrideType) Sets the perspective category. Takes a String (one of landingpage, genericcontainer, workspace, sidepanel-left, sidepanel-right, or a custom registered type) or a SmartViewEnums.PerspectiveType. Required 4.1.0
layout(layout) Sets the widget layout. Required 4.1.0
global() Makes the perspective global (system-wide). This is the default scope 4.1.0
local(node, cascading) Makes the perspective a local override on a CSNode. The user needs Modify permission on the node. cascading applies it to descendants 4.1.0
local(nodeId, cascading) Same as above, with a DataID 4.1.0
scope(scope) Sets the scope explicitly, as a String (global, local) or a SmartViewEnums.Scope 4.1.0
cascading(cascading) Sets the cascading flag. Used with local scope only 4.1.0
rule(rule) Adds one rule condition and makes the perspective rule-based 4.1.0
rules(rules) Replaces the list of rule conditions 4.1.0
containerTypes(subTypes...) Sets the container subtypes a container perspective targets 4.1.0
workspaceType(workspaceType) Sets the workspace type a workspace perspective targets 4.1.0
perspectiveInfo(perspectiveInfo) Sets the raw type-specific perspective information. containerTypes and workspaceType set the same value 4.1.0
parent(parent) Sets the container where a new perspective node is stored. Defaults to the Perspectives Volume. Ignored on update 4.1.0
names(names) Sets multilingual node names, as a map of locale to name. Overrides title for the node name 4.1.0
comments(comments) Sets multilingual descriptions, as a map of locale to description 4.1.0
enabled(enabled) Sets whether the perspective is enabled. Default true 4.1.0
constantData(constantData) Sets the layout dependency (constant) data list 4.1.0
attribute(key, value) Sets an extra field on the saved item, for example departmentId, assetContainerId, or pnodepath 4.1.0
existing(perspective) / existing(perspectiveId) Marks the request as an update of an existing perspective. Use it with saveAllPerspectives 4.1.0
createPerspective() Shortcut for amsui.createPerspective(this) 4.1.0
updatePerspective(perspective) Shortcut for amsui.updatePerspective(perspective, this) 4.1.0

Constants on the class give the raw values: TYPE_LANDINGPAGE, TYPE_GENERIC_CONTAINER, TYPE_WORKSPACE, TYPE_SIDEPANEL_LEFT, TYPE_SIDEPANEL_RIGHT, SCOPE_GLOBAL, and SCOPE_LOCAL.

Shortcuts need a bound request

createPerspective() and updatePerspective(node) on the request only work when the request came from amsui.newPerspectiveRequest() or CSPerspective.toRequest(). Otherwise they throw InvalidParamException.

Batch saves

saveAllPerspectives(requests) sends up to 10 requests in one call. Requests marked with existing(...) are updates; the others are creates. If one item fails, the whole batch is rolled back. The list must not be empty or longer than 10. When several requests set parent(), the first one is used for the whole batch.

Reading, Updating, and Deleting

getPerspective and getPerspectives return CSPerspective objects. They are read-only snapshots.

Property Description Since
id Perspective node DataID 4.1.0
activeVersionId Active version id of the perspective 4.1.0
title Perspective title (node name) 4.1.0
overrideType Perspective category, for example landingpage or genericcontainer 4.1.0
scope global or local 4.1.0
appliesToNodeId For local perspectives, the node the perspective applies to 4.1.0
appliesToNodePath For local perspectives, the path of that node 4.1.0
cascading For local perspectives, whether the override cascades to descendants 4.1.0
perspectiveInfo Type-specific value, for example container subtypes 4.1.0
layout The widget layout, as a CSPerspectiveLayout 4.1.0
rules Rule conditions, when the perspective is rule-based 4.1.0
constantData Layout dependency (constant) data 4.1.0
constantExtractionMode Client-side constant extraction mode hint 4.1.0
priority Perspective priority / ordering hint 4.1.0
perspectiveNodePath Path of the perspective node in the Perspectives Volume 4.1.0
node The perspective node, as a CSNode 4.1.0
Method Description Since
toRequest() Returns a CSPerspectiveRequest seeded with the title, type, scope, layout, rules, constant data, perspective information, and the perspective id. Use it for a read, modify, update flow 4.1.0

What toRequest() does not copy

The seeded request does not carry multilingual names, comments, or the enabled flag. Set them again if your update should change them.

The layout of a read perspective is a generic CSPerspectiveLayout. Its widgets come back as plain maps, not as typed widget builders. To change widgets, either build a new layout, or set a zone or option again with zone(...), widget(...), or option(...).

Deleting a perspective. The amsui service has no delete method. A perspective is a node, so delete it with the standard node API, for example perspective.node.delete(). If you only want to switch it off, use disablePerspective.

Layouts

A layout sets the arrangement (type) and the options that hold the widgets. Some layouts use named zones, others use an ordered array of widgets.

Method Description Since
amsui.newLayout(type) Creates a generic layout for a String type or a SmartViewEnums.LayoutType 4.1.0
amsui.newFlowLayout() Creates a CSFlowLayout 4.1.0
amsui.newLeftCenterRightLayout() Creates a CSLeftCenterRightLayout 4.1.0

Layout types

Layout type LayoutType constant How widgets are placed
flow FLOW Ordered widgets array. Use CSFlowLayout or widget(...)
tabbed-flow TABBED_FLOW Ordered widgets array. Use widget(...)
grid GRID Ordered widgets array. Use widget(...)
left-center-right LEFT_CENTER_RIGHT Zones left, center, right, one widget each. Use CSLeftCenterRightLayout
single SINGLE One zone named widget. Use zone("widget", widget)
banner-content-sidebar BANNER_CONTENT_SIDEBAR Zones banner, content, sidebar, each a list of widgets. Use zone(name, list)
sidepanel-left SIDE_PANEL_LEFT Same zones as banner-content-sidebar
sidepanel-right SIDE_PANEL_RIGHT Same zones as banner-content-sidebar
tabbed TABBED Tab and grid based. Not authored through the zone or array model
zone ZONE Generic zone layout. Use zone(...) or option(...)

CSPerspectiveLayout also exposes these values as constants: TYPE_FLOW, TYPE_TABBED_FLOW, TYPE_LEFT_CENTER_RIGHT, TYPE_GRID, TYPE_SINGLE, TYPE_TABBED, TYPE_ZONE, TYPE_BANNER_CONTENT_SIDEBAR, TYPE_SIDEPANEL_LEFT, and TYPE_SIDEPANEL_RIGHT.

flowchart TD
    chooseLayout{"Layout type"} -->|"flow, tabbed-flow, grid"| arrayLayout["widgets array<br/>addWidget / widget"]
    chooseLayout -->|"left-center-right"| lcrLayout["left, center, right<br/>one widget per zone"]
    chooseLayout -->|"single"| singleLayout["zone widget<br/>one widget"]
    chooseLayout -->|"banner-content-sidebar, sidepanel-left, sidepanel-right"| listZones["banner, content, sidebar<br/>list of widgets per zone"]
    arrayLayout --> perspectiveLayout["perspective layout<br/>type + options"]
    lcrLayout --> perspectiveLayout
    singleLayout --> perspectiveLayout
    listZones --> perspectiveLayout

Generic layout (CSPerspectiveLayout)

Method Description Since
type(type) Sets the layout type, as a String or a SmartViewEnums.LayoutType 4.1.0
zone(zone, widget) Puts one widget into a named zone (one-widget-per-zone layouts) 4.1.0
zone(zone, widgets) Puts a list of widgets into a named zone (list-zone layouts) 4.1.0
widget(widget) Appends a widget to the widgets array (array layouts) 4.1.0
option(key, value) Sets a raw layout option. The value can be a widget, a list of widgets, or a plain value 4.1.0

Flow layout (CSFlowLayout)

A flow layout is an ordered list of tiles. It extends CSPerspectiveLayout.

Method Description Since
addWidget(widget) Appends a widget to the flow 4.1.0
widgets(widgets) Replaces the whole ordered list of widgets 4.1.0

Left-center-right layout (CSLeftCenterRightLayout)

Three named zones, one widget each. It extends CSPerspectiveLayout.

Method Description Since
left(widget) Puts a widget in the left zone. Sets its kind to tile if you did not set one 4.1.0
center(widget) Puts a widget in the center zone. Sets its kind to fullpage if you did not set one 4.1.0
right(widget) Puts a widget in the right zone. Sets its kind to tile if you did not set one 4.1.0

Only three zones are saved

A zone you leave empty is saved as an empty object. This layout saves only left, center, and right. Anything you add with option(...) or widget(...) on a CSLeftCenterRightLayout is dropped.

Rules

Rules make a perspective apply only when conditions are met. Create a condition with amsui.newRule() and add it to the request with rule(...) or rules(...).

Method Description Since
amsui.newRule() Creates an empty CSPerspectiveRule 4.1.0
type(type) Sets the rule type. It must match a rule type registered in the Content Server Rules subsystem 4.1.0
operator(operator) Sets the operator. Valid operators depend on the rule type 4.1.0
value(value) Sets the value the operator is applied to 4.1.0
logicPrefix(logicPrefix) Joins this condition to the previous one, as a String or a SmartViewEnums.LogicPrefix (AND, OR) 4.1.0
attribute(key, value) Sets an extra key on the condition 4.1.0

Rules are not validated

The values pass through to Content Server without deep validation. A wrong rule type or operator surfaces only when Content Server saves or evaluates the perspective.

Widgets

Every widget extends CSPerspectiveWidget. Use a typed factory when one exists, because it sets the widget module and a sensible default kind. Use amsui.newWidget(...) for any other widget.

Common widget methods (CSPerspectiveWidget)

Method Description Since
amsui.newWidget(type) Creates a generic widget for any widget module id (for example csui/widgets/nodestable) or a SmartViewEnums.Widget 4.1.0
type(type) Sets the widget module id 4.1.0
kind(kind) Sets the widget size, as a String or a SmartViewEnums.WidgetKind (TILE, WIDE_TILE, HEADER, FULLPAGE, HERO_TILE). Support depends on the widget 4.1.0
id(id) Sets a stable, unique widget id 4.1.0
option(key, value) Sets one widget option 4.1.0
options(options) Merges a map of widget options 4.1.0
attribute(key, value) Sets an extra top-level key on the widget configuration 4.1.0
hidden(hidden) Marks the widget hidden or visible 4.1.0

Set widget ids when you update

When you do not call id(...), a new random id is generated each time the widget is saved. Set a fixed id if anything depends on the widget keeping the same id across updates.

Typed builders only cover the best-known options. You can always add more with option(key, value).

Module Suite Content Script tiles

These tiles get their content from a Content Script data source. See Smart UI Tiles for what each data source returns. They all extend CSContentScriptWidget, whose default kind is tile.

Common tile methods (CSContentScriptWidget)

Method Description Since
source(scriptId) / source(script) Sets the Content Script that provides the tile content, by DataID or CSNode 4.1.0
parameter(name, value) Adds a parameter passed to the data source. The value is converted to a string 4.1.0
header(header) Shows or hides the tile header 4.1.0
title(title) Sets the header title 4.1.0
titleBarIcon(titleBarIcon) Sets the header icon as a CSS class from the Smart View icon set 4.1.0
amIcon(amIcon) Sets the header icon from the Module Suite icon set, for example am_icon_chart_bar 4.1.0
iconSchema(schema) Sets the Module Suite icon colour, as a String (for example am_icon_teal) or a SmartViewEnums.IconSchema (GREEN, BLUE, RED, YELLOW, TEAL, PURPLE, GREY, ORANGE) 4.1.0
scroll(scroll) Makes the tile body scrollable 4.1.0
loadConf(loadConf) Loads the widget configuration from the data source 4.1.0
contextAware(contextAware) Makes the tile react to the current node 4.1.0
tileClasses(cssClasses) Adds space-separated CSS classes to the tile container 4.1.0

Content Script tile (CSContentScriptTileWidget)

Runs a Content Script and renders its result in the tile body. Factory: amsui.newContentScriptTileWidget(). Module: anscontentsmartui/widgets/tile_content_script.

Method Description Since
expandable(expandable) Lets the user expand the tile 4.1.0
expandMode(mode) Sets how the tile expands: dialog or panel, or a SmartViewEnums.ExpandMode 4.1.0
expandClass(className) Sets the size of the expanded slide panel, as a class such as amsui-smartui-slide-panel-50vw or a SmartViewEnums.SlidePanelSize (VW_30 to VW_100, in steps of 10) 4.1.0
expandTitle(title) Sets the title of the expanded view 4.1.0
expandHeader(header) Shows a header in the expanded view 4.1.0
expandSource(scriptId) Sets the Content Script that renders the expanded view 4.1.0
expandParameter(name, value) Adds a parameter for the expanded-view script 4.1.0
hamburgerSource(scriptId) Sets the Content Script rendered in the hamburger menu 4.1.0
hamburgerParameter(name, value) Adds a parameter for the hamburger-menu script 4.1.0
hamburgerWidth(width) Sets the hamburger-menu panel width as a viewport percentage string, from 10 to 100 4.1.0

Content Script nodes table tile (CSContentScriptNodesTileWidget)

A node table whose rows come from a Content Script. Factory: amsui.newContentScriptNodesTileWidget(). Module: anscontentsmartui/widgets/tile_content_script_nodes. Default kind: fullpage.

Method Description Since
pageSize(pageSize) Sets the number of rows per page 4.1.0

Chart tile (CSChartTileWidget)

A Chart.js chart fed by a Content Script that returns JSON. Factory: amsui.newChartTileWidget(). Module: anscontentsmartui/widgets/tilechart_content_script.

Method Description Since
chartType(chartType) Sets the chart type: pie, bar, line, doughnut, radar, polarArea, bubble, or a SmartViewEnums.ChartType 4.1.0
chartId(chartId) Sets the unique client id of the chart 4.1.0
chartRefreshTime(seconds) Sets the auto-refresh interval in seconds, as a string. 0 means no refresh 4.1.0
chartSize(chartSize) Sets the chart width: full, one-third, half, two-thirds, or a SmartViewEnums.ChartSize 4.1.0

Tree tile (CSTreeTileWidget)

A lazily loaded tree fed by a Content Script that returns JSON. Factory: amsui.newTreeTileWidget(). Module: anscontentsmartui/widgets/tiletree_content_script.

Method Description Since
treeId(treeId) Sets the unique client id of the tree 4.1.0

These factories return a plain CSContentScriptWidget, so only the common tile methods apply.

Factory Module Since
amsui.newLinksTileWidget() anscontentsmartui/widgets/tilelinks_content_script 4.1.0
amsui.newLinkTilesTileWidget() anscontentsmartui/widgets/tilelinkstiles_content_script 4.1.0
amsui.newNewsTileWidget() anscontentsmartui/widgets/tilenews_content_script 4.1.0

Shell content tile (CSShellTileWidget)

Hosts a Shell Page in a perspective tile. Factory: amsui.newShellTileWidget(). Module: anscontentsmartui/widgets/tile_content_shell. Shell Pages themselves are described in Shell pages and Shell components.

Method Description Since
userContextSource(scriptId) / userContextSource(script) Sets an optional Content Script that the Shell runtime uses to enrich the user context 4.1.0

Smart View widgets

Nodes table (CSNodesTableWidget)

A browsable table of a container's children. Factory: amsui.newNodesTableWidget(). Module: csui/widgets/nodestable. Default kind: fullpage.

Method Description Since
containerId(containerId) / container(container) Sets the container whose children are listed, by DataID or CSNode 4.1.0
pageSize(pageSize) Sets the initial page size 4.1.0
pageSizes(pageSizes) Sets the list of page sizes the user can pick 4.1.0

Metadata and Metadata Navigation (CSMetadataWidget)

Shows the metadata of one node. Factories: amsui.newMetadataWidget() (module csui/widgets/metadata) and amsui.newMetadataNavigationWidget() (module csui/widgets/metadata.navigation). Default kind: fullpage.

Method Description Since
nodeId(id) / node(node) Sets the node whose metadata is shown. Required 4.1.0
initialPanel(initialPanel) Sets the panel shown first 4.1.0

Permissions, Document Overview, Version Overview (CSNodeIdWidget)

Full-page widgets whose only option is a target node. Default kind: fullpage.

Factory Module Since
amsui.newPermissionsWidget() csui/widgets/permissions 4.1.0
amsui.newDocumentOverviewWidget() csui/widgets/document.overview 4.1.0
amsui.newVersionOverviewWidget() csui/widgets/version.overview 4.1.0
Method Description Since
nodeId(id) / node(node) Sets the target node. Required 4.1.0

HTML editor (CSHtmlEditorWidget)

The wiki / HTML editor widget. Factory: amsui.newHtmlEditorWidget(). Module: csui/widgets/html.editor. Default kind: tile.

Method Description Since
title(title) Sets the widget title 4.1.0
wikiContainerId(wikiContainerId) Sets the wiki container node 4.1.0
wikiTemplateId(wikiTemplateId) Sets the wiki template node 4.1.0
wikiId(wikiId) Sets the wiki id 4.1.0
wikiPageId(wikiPageId) Sets the wiki page id 4.1.0

Shortcuts (CSShortcutsWidget)

Up to four shortcut tiles to nodes. Factory: amsui.newShortcutsWidget(). Module: csui/widgets/shortcuts. Default kind: tile.

Method Description Since
theme(theme) Sets the theme, as a CSS class such as csui-shortcut-theme-teal1 or a SmartViewEnums.ShortcutTheme (STONE_1, STONE_2, TEAL_1, TEAL_2, PINK_1, PINK_2, INDIGO_1, INDIGO_2) 4.1.0
addShortcut(id) Adds a shortcut to a node DataID. The widget supports at most 4 items 4.1.0
addShortcut(shortcut) Adds a shortcut item map with id, type, displayName, customBackgroundImage, customBackgroundColor 4.1.0
shortcutItems(shortcutItems) Replaces the whole list of shortcut item maps 4.1.0

Custom search (CSCustomSearchWidget)

Renders a saved search query. Factory: amsui.newCustomSearchWidget(). Module: csui/widgets/search.custom. Default kind: tile.

Method Description Since
savedSearchQueryId(savedSearchQueryId) Sets the saved search query by id (String or number). Required 4.1.0
savedSearchQuery(savedSearchQuery) Sets the saved search query by CSNode. Required 4.1.0

Preset widgets

These factories return a generic CSPerspectiveWidget with the module and kind already set. Configure them with option(...) and options(...).

Factory Module Default kind Since
amsui.newMyAssignmentsWidget() csui/widgets/myassignments tile 4.1.0
amsui.newSearchResultsWidget() csui/widgets/search.results fullpage 4.1.0
amsui.newSearchResultsTableWidget() csui/widgets/search.results.table fullpage 4.1.0
amsui.newFavoritesTableWidget() csui/widgets/favorites2.table tile 4.1.0
amsui.newRecentlyAccessedTableWidget() csui/widgets/recentlyaccessedtable tile 4.1.0
amsui.newRecycleItemsTableWidget() csui/widgets/recycle.items.table tile 4.1.0
amsui.newNavigationHeaderWidget() csui/widgets/navigation.header header 4.1.0

SmartViewEnums.Widget lists the module ids of all the widgets on this page, so amsui.newWidget(SmartViewEnums.Widget.MY_ASSIGNMENTS) is equivalent to a generic builder for that module, without a preset kind.

Other 4.1.0 Smart UI Service Members

Method Description Since
overrides(overrides) Returns an OverrideBuilder that edits the override map in an override script. See Smart View Overrides 4.1.0
createPage(parent, viewName, body, pageRenderer) Creates a Smart Page and stores a SmartViewEnums.PageRenderer (SHELL or SHELL_COMPONENT) in its ExtendedData. A null renderer creates a classic Smart Page. See Shell pages and Shell components 4.1.0
createPage(parent, viewName, body, extData) Creates a Smart Page and merges the given map into its ExtendedData 4.1.0

Module Suite 4.1.0 also adds these scripting services for the Application Builder. They support the builder itself and are not covered here.

Service Description Since
appbuilderproject Project-level operations for the Application Builder 4.1.0
appbuilderlint Content Server-authoritative lint for Application Builder generation 4.1.0
appbuildersetup Executes explicitly approved Application Builder setup scripts 4.1.0
appbuilderfulfillment Inspects and fulfills Application Builder configuration objects 4.1.0

Examples

Example: global landing page with a flow of tiles

def dashboardScript = docman.getNodeFast(111111L)  // Content Script data source
def chartScript     = docman.getNodeFast(222222L)  // Content Script returning chart JSON

def overview = amsui.newContentScriptTileWidget()
    .expandable(true)
    .expandMode(SmartViewEnums.ExpandMode.PANEL)
    .expandClass(SmartViewEnums.SlidePanelSize.VW_60)
    .source(dashboardScript)
    .parameter("mode", "summary")
    .title("Overview")
    .amIcon("am_icon_chart_bar")
    .iconSchema(SmartViewEnums.IconSchema.TEAL)
    .id("overview-tile")

def chart = amsui.newChartTileWidget()
    .chartType(SmartViewEnums.ChartType.BAR)
    .chartId("docsByType")
    .chartSize(SmartViewEnums.ChartSize.HALF)
    .chartRefreshTime("60")
    .source(chartScript)
    .title("Documents by type")
    .id("docs-chart")

def shortcuts = amsui.newShortcutsWidget()
    .theme(SmartViewEnums.ShortcutTheme.TEAL_1)
    .addShortcut(2000L)
    .id("home-shortcuts")

def layout = amsui.newFlowLayout()
    .addWidget(overview)
    .addWidget(chart)
    .addWidget(shortcuts)
    .addWidget(amsui.newMyAssignmentsWidget().id("my-assignments"))

def node = amsui.newPerspectiveRequest()
    .title("Company Landing Page")
    .type(SmartViewEnums.PerspectiveType.LANDING_PAGE)
    .global()
    .layout(layout)
    .createPerspective()

out << (node ? "Created perspective ${node.ID}" : "Saved, but the new node could not be resolved")

Example: local left-center-right perspective on a folder

def folder = docman.getNodeFast(333333L)

def layout = amsui.newLeftCenterRightLayout()
    .left(amsui.newMetadataWidget().node(folder).id("project-meta"))
    .center(amsui.newNodesTableWidget().container(folder).pageSize(50).pageSizes([25, 50, 100]).id("project-table"))
    .right(amsui.newCustomSearchWidget().savedSearchQueryId(123456L).id("project-search"))

def node = amsui.newPerspectiveRequest()
    .title("Projects Perspective")
    .type(SmartViewEnums.PerspectiveType.GENERIC_CONTAINER)
    .local(folder, true)
    .layout(layout)
    .names(["en_US": "Projects Perspective", "it_IT": "Prospettiva Progetti"])
    .comments(["en_US": "Created by script"])
    .createPerspective()

Example: rule-based container perspective

// ruleType must be a rule type registered in the Content Server Rules subsystem;
// the valid operator and value depend on that rule type.
def rule = amsui.newRule()
    .type(params.ruleType)
    .operator(params.ruleOperator)
    .value(params.ruleValue)

def layout = amsui.newLayout(SmartViewEnums.LayoutType.SINGLE)
    .zone("widget", amsui.newNodesTableWidget().id("rule-table"))

amsui.newPerspectiveRequest()
    .title("Folders by rule")
    .type(SmartViewEnums.PerspectiveType.GENERIC_CONTAINER)
    .containerTypes(0)
    .rule(rule)
    .layout(layout)
    .createPerspective()

Example: zones with lists of widgets

def layout = amsui.newLayout(SmartViewEnums.LayoutType.BANNER_CONTENT_SIDEBAR)
    .zone("banner",  [amsui.newNavigationHeaderWidget().id("nav-header")])
    .zone("content", [amsui.newRecentlyAccessedTableWidget().id("recent"),
                      amsui.newFavoritesTableWidget().id("favorites")])
    .zone("sidebar", [amsui.newLinksTileWidget().source(98765L).title("Links").id("links")])

Example: read, modify, and update

def folder = docman.getNodeFast(333333L)
def perspectives = amsui.getPerspectives(folder)

perspectives.each { p ->
    out << "${p.id} ${p.title} ${p.overrideType} ${p.scope} cascading=${p.cascading}<br/>"
}

def current = perspectives.find { it.title == "Projects Perspective" }
if (current) {
    def newLayout = amsui.newLeftCenterRightLayout()
        .center(amsui.newNodesTableWidget().container(folder).pageSize(100).id("project-table"))

    amsui.updatePerspective(current.id, current.toRequest().layout(newLayout))
}

Example: batch create and update

def existing = amsui.getPerspective(445566L)

def update = existing.toRequest()
    .layout(amsui.newFlowLayout().addWidget(amsui.newMyAssignmentsWidget().id("my-assignments")))

def create = amsui.newPerspectiveRequest()
    .title("Search Landing Page")
    .type(SmartViewEnums.PerspectiveType.LANDING_PAGE)
    .layout(amsui.newLayout(SmartViewEnums.LayoutType.SINGLE)
        .zone("widget", amsui.newSearchResultsWidget().id("search-results")))

// Both items succeed or both are rolled back. A request from toRequest() already
// carries the perspective id; use existing(...) for requests built from scratch.
amsui.saveAllPerspectives([update, create])

Example: disable, enable, and delete

def p = amsui.getPerspective(445566L)

amsui.disablePerspective(p.node)
// ...
amsui.enablePerspective(p.id)

// amsui has no delete method: delete the perspective node itself.
p.node.delete()