Skip to content

Buttons

The primary purpose of this service is to provide buttons to display on the Portals main menu toolbar and the views.

To see the Buttons menu entry on the Portal, the buttons=view permission is required.

For a summary of permission names and uses related to this service, please refer to this section.

Note

If you have the buttons=* permission, you will have access to all the functions mentioned below.

List and view buttons

To list and display all buttons, the buttons=read permission is required.

List buttons

If your permission has values such as: buttons=read('Button 1', 'Button 2'), you will only see the listed buttons.

You can view a button by clicking on the magnifier icon in the ‘Actions’ column.

View a button

Edit a button

To create, update, rename, duplicate, export or import buttons, the buttons=edit permission is required.

To delete buttons, the buttons=delete permission is required.

Double-click on a row of the table display or click on the pen icon to edit a button.

Edit a button

Type

A MENU button will be added to the standard UI menu if the users buttons=display permission checks succeed.

A VIEW button when referenced as a defined and if the users permission allow, will cause a button to be added to each row of the transaction/workflow task grid and the top row of the individual transaction view (i.e. after double clicking on a transaction row)

Handlers

Permissions

The permission buttons=display is required to access the following endpoints. You can also restrict access to specific buttons (i.e. buttons=display("button1", "button2"))

You can define other arguments in the uri to be passed to the script through the pipeline.

Notice

The URI must start with p6cmb://. The primary target for button calls is the script service but any p6 service can be called via this mechanism.

Variables will be provided to the script throw the pipeline:

  • locale: the locale of the connected user

Button VIEW type only

  • viewName: the name of the current view
  • platform6.request.dataPartition: the dataPartition of the current view
  • platform6.request.dataType: the dataType of the current view
  • platform6.request.ids.X: the id of the selected item in the view (where X is 0 indexed number)

Before rendering

The button can be configured with a before render handler. It is the uri of the target destination of a message through the Common Message Bus.

For example, you can define a script as target: p6cmb://scripts?platform6.request.action=execute&id=BeforeButtonRender

Pipeline variables

Specific variables will be provided to the script throw the pipeline:

  • defaultLabel: the default localized label
  • defaultTooltip: the default localized tooltip
  • defaultStyle: the default style
  • defaultIcon: the default icon
  • defaultWeight: the default weight (for MENU only)
Pipeline response

In response, the script can write into the pipeline the following entries prefixed by the transaction item ids:

  • {key}.style: css classes to be applied to the button
  • {key}.label: button label to be displayed (use the p6.i18n DSL to retrieve localized text)
  • {key}.icon: css classes to be applied to the icon. (If empty no icon will be displayed)
  • {key}.display: should we display the button (true by default).

For MENU only:

  • {key}.weight: position of the button in the Platform6 main menu (should be an integer)

Notice

If the output pipeline entries are missing then the default configuration of the button will be used

Notice

For menu button type, {key} should be set to “menu”

Examples
Menu
p6.pipeline.put("menu.label", "Custom override")
p6.pipeline.put("menu.icon", "fa-fw fa fa-bolt")
p6.pipeline.put("menu.weight", "100")
p6.pipeline.put("menu.display", "true")
Transaction
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;

def label = [
        EN: "items to pay",
        FR: "articles à payer"
]

def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
    println " > Processing: " + pk
    def key = pk.getItemIds().join(",")

    def item = p6.transaction.get(pk)
    def transactionInfo = xmlSlurper.parseText(item)
    def count = transactionInfo.KeyValue.find{it.Key == 'Line items'}.Value.text()
    p6.pipeline.put("${key}.label", "${count} " + p6.i18n.getText(label))
    p6.pipeline.put("${key}.style", "btn-trans btn-success")
    if(count.toInteger() > 10) {
        p6.pipeline.put("${key}.style", "btn-trans btn-danger")    
    }
    if(count.toInteger() == 0) {
        p6.pipeline.put("${key}.display", "false")
    }
}

On click

The button can be configured with an on click render handler. It is the uri of the target destination of a message through the Common Message Bus.

For example, you can define a script as target: p6cmb://scripts?platform6.request.action=execute&id=OnButtonClick

Response

In response, the service can write into the pipeline the following entries:

  • ui.action: the action to be returned to the UI:

    • POPUP_MESSAGE: Simple message popups containing locale specific text

    • OPEN_JOBS: Open the jobs panel so the user can see job progress and download generated payloads

    • OPEN_VIEW: This will open a transactions list panel with the given view id

    • OPEN_DASHBOARD: This will open a specific dashboard

    • REFRESH_CURRENT_VIEW: Force the refresh of the current page view of transactions or workflow tasks

    • NEW_FORM: This causes the UI to call the new Forms Service to retrieve the definition and render the named form

    • WEB_LINK: Open the given url in a new tab

    • INDICATOR: Return an execution indicator

    • DISPLAY: Display a content managed by the script (could be html, xml, txt, csv or pdf)

    • DOWNLOAD: Download a generated file

Notice

Only the script service is capable of reading and writing to/from the pipeline. Other services must read/write the Platform 6 Common Message directly to adhere to this implied Request/Response contract. If the call succeeds a success action will be returned. Otherwise, a failure will be returned, and a warning is displayed in the log of Platform 6.

The following action requires additional parameters:

ui.action=POPUP_MESSAGE

  • popup.type: the type of the popup (allowed values are: ERROR, INFO, WARNING, SUCCESS)
  • popup.title: the title of the popup
  • popup.message: the message of the popup
Open view

ui.action=OPEN_VIEW

  • view.name: the name of the view to be displayed
New form

ui.action=NEW_FORM

  • form.id: the id of the form to be displayed
  • form.property.: (optional) a set of properties to be passed to the form ( Since 6.9.3)

Note

Properties will be available in the form pipeline. Key prefix form.property. will be removed.

Example

form.property.fee=Fee

will generate the following pipeline variable

fee=Fee

ui.action=WEB_LINK

  • link.url: the url to be opened in a new tab
Open dashboard

ui.action=OPEN_DASHBOARD

  • dashboard.name: the name of the dashboard to be displayed
Display

Since 6.9.2

ui.action=DISPLAY

  • display.content: the content to be displayed
  • display.path: the file path to the content
  • display.type: the type of content to be displayed (CSV, XML, TXT, HTML, or PDF) - Default value is HTML
  • display.mode: the way content should be displayed (MODAL or PAGE) - Default value is PAGE

Note

display.path will be read first if set and fallback to display.content.

If display.path is used:

  • display.type will be set to the known type matching the extension (if not already defined)
  • display.content will be set with the content of the file at display.path

Security

Only paths matching p6.allowed.paths are allowed.

Known types only

If the defined type display.type is unknown, the display.content will contain an error message and the type will be set to TXT

Examples
Display a local file
p6.pipeline.put("ui.action", "DISPLAY")
p6.pipeline.put("display.path", "p6file://${P6_DATA}/path/to/file.pdf")
Display a content
p6.pipeline.put("ui.action", "DISPLAY")
p6.pipeline.put("display.content", "fee,foo,true,123")
p6.pipeline.put("display.type", "CSV")
p6.pipeline.put("display.mode", "MODAL")
Migrating from SDOC

SDOC feature was design to allow smart display of files attached to a transaction.

It can now be done using button DISPLAY action according to the following examples:

Examples

Display a transaction file
p6.button.createDisplayFromPipeline(
    [xpath: '/TransactionInfo/SourceDocumentURI']
cf p6.button.createDisplayFromPipeline documentation

Display manually a document
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;

def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
    def item = p6.transaction.get(pk)
    def transactionInfo = xmlSlurper.parseText(item)
    p6.pipeline.put("display.path", transactionInfo.SourceDocumentURI.text())
}

p6.pipeline.put("ui.action", "DISPLAY")
Download

Since 6.9.2

ui.action=DOWNLOAD

  • download.content: the content as string
  • download.path: the file path to the content
  • download.contentType: the content type of the attachment - Default value is application/octet-stream
  • download.filename: the filename of the attachment - Default value is download.dat

Note

download.path will be read first if set and fallback to download.content

Security

Only paths matching p6.allowed.paths are allowed.

Examples
Download a local file
p6.pipeline.put("ui.action", "DOWNLOAD")
p6.pipeline.put("download.contentType", "application/csv")
p6.pipeline.put("download.filename", "data.csv")
p6.pipeline.put("download.path", "p6file://${P6_DATA}/path/to/file.ext")
Download a file
p6.pipeline.put("ui.action", "DOWNLOAD")
p6.pipeline.put("download.contentType", "application/csv")
p6.pipeline.put("download.filename", "data.csv")
p6.pipeline.put("download.content", "fee,foo,true,123")
Migrating from SURI

SURI feature was design to allow smart download of files attached to a transaction.

It can now be done using button DOWNLOAD action according to the following examples:

Examples

Download a transaction file
p6.button.createDownloadFromPipeline(
    '/TransactionInfo/SourceDocumentURI',
    '/TransactionInfo/SourceDocumentContentType'
)
cf p6.button.createDownloadFromPipeline documentation

Download manually a document
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;

def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
    def item = p6.transaction.get(pk)
    def transactionInfo = xmlSlurper.parseText(item)
    p6.pipeline.put("download.filename", "transaction.xml")
    p6.pipeline.put("download.contentType", "text/xml")
    p6.pipeline.put("download.path", transactionInfo.SourceDocumentURI.text())
}

p6.pipeline.put("ui.action", "DOWNLOAD")

The following action accepts optional parameters:

Indicator

ui.action=INDICATOR

  • indicator.success: is the indicator on success (true by default)
  • indicator.message: the indicator message
Examples
Menu
p6.pipeline.put("ui.action", "POPUP_MESSAGE")
p6.pipeline.put("popup.type", "INFO")
p6.pipeline.put("popup.title", p6.i18n.getText([EN: "Payment", FR: "Paiement"]))
p6.pipeline.put("popup.message", "Message to be displayed")
Transaction
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;

def xmlSlurper = new XmlSlurper()
p6.transaction.getPKsUsingPipelineRequest().each { pk ->
    println " > Processing: " + pk
    /*
    def item = p6.transaction.get(pk)
    def transactionInfo = xmlSlurper.parseText(item)
    ... some logic
    */
}

p6.pipeline.put("ui.action", "REFRESH_CURRENT_VIEW");
Workflow
import groovy.json.*;
import io.platform6.core.api.datapartition.DataPartitionType;

p6.transaction.getPKsUsingPipelineRequest().each { pk ->
    println " > Processing: " + pk

    p6.transaction.getItemLinks(pk, p6.pipeline.get('viewName')).each { itemLink ->
        println "  > ItemLink: " + itemLink
    }
}

p6.pipeline.put("ui.action", "REFRESH_CURRENT_VIEW");