Unify and manage your data

Script

Learn about custom scripts needed for custom components.

Every custom component requires a custom script. Specify the script file in the action property of the component's UI configuration.

Important: Custom script is executed inside the sandbox and does not have access to the DOM tree of the UI client, local storage, or any other parameters directly. However, there is a way to communicate with the UI client and execute different actions. To do this, you must use global object UI in your custom script and call async methods on this object.

General

The following example shows the API path and UI configuration of a custom component. The linked script (iframe.js) uses this configuration to render a B2B integration view and call alerts on the UI client.

{
  "id": "bbChartView",
  "component": "CustomActionView",
  "caption": "B2B Integration",
  "url": "https://cgraph-dev.reltio.com/custom-graph/bbChart?entityUri=",
  "height": 200,
  "action": {
    "files": [
      "https://dl.dropboxusercontent.com/u/465285497/iframe.js"
    ]
  }
} 

UI Object methods

The global UI object provides methods that enable custom scripts to communicate with the UI client. The following table describes the available methods, their syntax, parameters, and usage.

MethodSyntaxDescriptionParametersNotes/Example
logUI.log(message)Logs a message for debugging.message (String | Object): Message or object to log.
setEnabledUI.setEnabled(value)Changes the enabled state of a control. Use only with custom buttons.value (Boolean): Specifies whether the control is enabled.
setVisibilityUI.setVisibility(value)Changes the visibility state of a control.value (String): visible, hidden, or excluded.
setHtmlUI.setHtml(html)Sets the widget's internal HTML. Use only with custom views.html (String): HTML content.
setChildHtmlUI.setChildHtml(id, html)Sets the internal HTML of a child widget. Use only with custom views.id (String): Child widget ID.html (String): HTML content.
setHeightUI.setHeight(height)Sets the widget height. Use only with custom buttons and custom views.height (Number): Height in pixels.
setWidthUI.setWidth(width)Sets the widget width. Use only with custom buttons and custom views.width (Number): Width in pixels.Correct parameter name from the current topic.
setToolTipUI.setToolTip(toolTip)Sets the widget tooltip.toolTip (String): Tooltip text.
onActionUI.onAction(function(){...})Entry point that runs after all scripts are loaded.NoneDeprecated. Use UI.onEvent() and listen for the "execute" event instead.
onEventUI.onEvent(function(type, data){...})Registers an event handler that runs when an event occurs.type (String): Event type.data (String | Object): Event-specific data.Supported events: execute, updateEntity, changeSearchQuery, changeVisibility, uiAction.
getEntityUriUI.getEntityUri()Retrieves the current entity URI.NoneReturns a Promise.
getEntityUI.getEntity()Retrieves the current entity.NoneReturns a Promise.
getApiPathUI.getApiPath()Retrieves the current API path.NoneReturns a Promise.
getSearchQueryUI.getSearchQuery()Retrieves the current search query.NoneReturns a Promise.
getTenantUI.getTenant()Retrieves the current tenant name.NoneReturns a Promise.
getPerspectiveUI.getPerspective()Retrieves the current perspective ID.NoneReturns a Promise.
setPerspectiveUI.setPerspective(perspective)Sets the current perspective.perspective (String): Perspective ID.Returns a Promise.
setEntityUriUI.setEntityUri(entityUri)Sets the current entity URI.entityUri (String): Entity URI.Returns a Promise.
apiUI.api(url, method, tenant, headers, data)Sends an API request or an external request.url (String): Request URL.method (String): GET, POST, PUT, or DELETE.tenant (String): Tenant name.headers (Object): Request headers.data (Object | String): Request body.Example: UI.api('https://test.reltio.com/nui/version', 'GET')
alertUI.alert(text)Displays an alert dialog.text (String): Alert message.Returns a Promise.
confirmUI.confirm(text)Displays a confirmation dialog.text (String): Confirmation message.Returns a Promise that resolves with the user's response.
promptUI.prompt(text, defaultText)Displays a prompt dialog.text (String): Prompt message.defaultText (String): Default value.Returns a Promise that resolves with the user's input.
getConfigurationUI.getConfiguration()Retrieves the metadata configuration.NoneReturns a Promise.
getUiConfigurationUI.getUiConfiguration()Retrieves the UI configuration of the current custom component.NoneReturns a Promise.
openSearchUI.openSearch(searchState)Opens the search screen with the specified state.searchState (Object): Search state JSON.Returns a Promise.

Supported event types

The onEvent() method supports the following event types:

Event Description
execute Triggered when a custom button or menu item is selected. The data parameter is null.
updateEntity Triggered when a new entity is loaded. The data parameter contains the entity JSON.
changeSearchQuery Triggered when the search criteria change. The data parameter contains the search query string.
changeVisibility Triggered when the visibility of a custom component changes. The data parameter is true or false.
uiAction Triggered when a specified UI action occurs on a DOM element in a custom view. The data parameter contains the action type, element ID, and event object.