Modules Dynamic items Action buttons - happy-geeks/wiser GitHub Wiki

The Actions object

Below is an overview of the specific properties of the action object (JSON). There are many more specific properties configurable for almost all types of actions, that is described further on in the documentation.

Property Mandatory Explanation
type yes The type of action to be performed. You can enter one of the following values (explanations of each possibility are further down):
  • openUrl
  • openUrlOnce
  • executeQuery
  • executeQueryOnce
  • openWindow
  • generateFile
  • updateItemLink
  • refreshCurrentItem
  • apiCall
  • pusher
  • custom
  • actionConfirmDialog
  • mergeFiles
  • userParameters no This is an array of objects of type 'userParameter'. This can be used to set any additional parameters that the user must fill in when performing the action. The user gets a popup per parameter where the values must be filled in. These same parameters can then be entered in the query (or any other action) and are then replaced with the values entered by the user.

    For each parameter you have a number of properties to set what kind of parameter it is, what kind of input field it should be etc. More information on this in the documentation on userParameters
    condition no It is possible to define a condition for each custom action. As long as all selected rows meet the conditions, the button will be visible to the user. To define this condition, a new attribute has been introduced on a custom action, named condition. The value of this attribute is an if-statement where data from the selected rows can be used. When the condition evaluates to true (for all selected rows), the button will be shown. For example, to check whether the column value of refunded_on is present, and the ID is an even number, you can write the following: "condition": "refunded_on && id % 2 == 0"

    openUrl

    This action can be used to open an (external) URL. If the button belongs to a grid, a separate URL is opened for each selected row.

    You can set the following properties here:

    • url: Indicates which URL should be opened.
      You can use in the URL all fields of the linked item as variables (i.e. by using {fieldName}) as well as following default variables:
      {itemTitle}: The title/name of the linked item.
      {itemId}: The ID of the linked item.
      {entityType}: The entity type of the linked item.
      {environment}: The published environment of the linked item (invisible, dev, test, acceptance or live).
      An example url would be: https://domain.com/{itemId}/?color={itemColor}
    • openIn: Controls how the URL should be opened. By default, window.open is used, which in most cases opens a new tab in the browser. If this option is set to kendoWindow, a popup from Kendo will be opened containing an iframe that loads the appropriate URL.
    • windowWidth: Allows the width of the popup to be set. This should be a string with for example 600px or 90%.
    • windowHeight: Allows you to set the height of the popup. This should be a string with, for example, 600px or 90%.

    openUrlOnce

    This is intended for grids. This opens only 1 URL for all selected items at once. All selected values are then passed comma separated to the URL, when variables are filled in for it, such as {selected_subaccountId}.

    Furthermore, the same options are available as with the openUrl action.

    executeQuery

    Allows you to execute a query in the database to which Wiser is linked. In that query, you can use all the fields of the linked item as variables. You do this by using the field name in the query encapsulated by brackets, for example {fieldname}. In addition, the following fixed variables can also be used:

    • {itemTitle}: The title/name of the linked item.
    • {itemId}: The ID of the linked item.
    • {entityType}: The entity type of the linked item.
    • {environment}: The published environment of the linked item (invisible, dev, test, acceptance or live).
    • For a grid which shows links between items you can also use: {selected_link_Id}

    You insert the query to be executed in the wiser_query table. You specify its ID in the action object as parameter 'queryId'. Alternatively, you can fill in the query in the wiser_entityproperty table in the column action_query.

    If you make sure that the last query returns a result with a column called itemId, then you can use the action openWindow to open that item in a popup afterward. For example, you can then enter a query that retrieves the id of a particular item, or you can have a query that adds a new item and then run this query in the end to retrieve the newest id: SELECT LAST_INSERT_ID() AS itemId;

    If fields from a link also need to be shown (from the table wiser_itemlinkdetail), then you should also make sure that your query returns the ID of that link last in a column linkId.

    If you want to use the result of a query to open a specific URL in a follow-up action of type OpenUrl you must have a column called urlPart and use {urlPart} as a replacement in the URL.

    It is also possible to show an error message to the user, which you return from the query. If you want to do this, make sure that your query returns the column success with value 0 and the column message containing the message to be shown to the user.

    Example action object JSON and example query:

    {
        "type": "executeQuery",
        "queryId": 8
    }

    Example Query:

    SELECT 
        i.id AS itemId,
        il.id AS linkId,
        IF(il.id IS NULL,0,1) AS success,
        'This is an error message for item if nothing is found' AS message
    FROM wiser_item i
    LEFT JOIN wiser_itemlink il ON il.item_id=i.id AND il.type=100
    WHERE i.title='{name_from_parameter}';
    
    INSERT INTO custom_table (id,color) VALUES ({itemId},'{color_from_parameter}');

    executeQueryOnce

    This can only be used for action buttons in grids. With normal executeQuery, the corresponding query is executed separately for each selected row in the grid. With executeQueryOnce, the query is executed only once for all selected rows at once. The selected values are given comma separated.

    openWindow

    Allows you to open a popup within the module containing the details of a specific item. The item that should be opened can be specified with the property 'itemId' and the link information can be added with the property 'linkId'. These values (itemId and linkId) can also be determined using a query provided it is executed using an 'executeQuery' action just before the 'openWindow' action.

    Example JSON:

    {
        "type": "openWindow",
        "itemId": 25,
        "linkId": 10
    }

    generateTextFile

    Allows you to generate a text file based on a query. For example, to generate an XML or CSV file from a stored procedure which is then offered for download.

    The following options are available:

    queryId: the query from wiser_query to be executed. Note that the result set from this query must always contain 1 row containing 2 columns. The first named 'result' and containing the text to be downloaded and the 2nd column named 'filename' and containing the file name for example generated.

    Example JSON:

    {
        "type": "generateTextFile",
        "queryId": 8
    }

    refreshCurrentItem

    Allows you to refresh the currently opened item, all data is retrieved and the user interface rebuilt in the process.

    refreshAllOpenedWindows

    This action refreshes all opened windows (within the same module). This includes the treeview or main grid, depending on the type of module opened.

    updateItemLink

    Note: This functionality only works for action buttons in a grid's toolbar!

    Allows the user to move an item link so that it is linked to another item (also known as 'rebooking'). This only works if the ID of the current link is known in the grid. This ID must then be in the grid's data in a column named linkId or link_id. If this column cannot be found, the user will receive an error message. The ID of the new item must be entered by the user in a popup.

    apiCall

    Allows calling an API. To do this enter an ID from the table wiser_api_connection in the property apiConnectionId. More information on populating that table can be found here: Connecting to external APIs TODO add link.

    pusher

    Allows to send a message to a logged-in user by pusher provided there is a subscription linked to this external tool. It is possible to set a channel and any additional information. By default, the channel 'agendering' is used. It is originally intended to send a notification to the user when a new agendering TODO (vertalen) is added.

    There must always be a pusherUserId, this can be done by filling a fixed ID in the options, or by using a userParameter in which a user can be chosen.

    The following settings are available:

    • channel: Optional: The channel the message should be sent to.
    • pusherUserId: Optional: The ID of the user that should receive the message. This can also be done via a userParameter, which must then have pusherUserId as the name.
    • EventData: Any extra data that should be sent with the message. This will only be used if programmed for the channel. At the time of writing, nothing has been created for this.

    Example settings:

    {
        "text": "pusher test",
        "icon": "notification",
        "style": "width: 400px",
        "actions": [
            {
                "type": "pusher",
                "channel": "calendar",
                "eventData": { "message": "This is a test" },
                "userParameters": [
                    {
                        "name": "userId",
                        "question": "choose a receiver",
                        "fieldType": "combobox",
                        "dataSource": "wiserUsers"
                    }
                ]
            }
        ]
    }

    custom

    If you want to run your own javascript, you can add an action of this type. This will prevent the user from getting the message that the button is not set up properly. You then have to make sure that you enter your own working javascript in the custom_script column of the table wiser_entityproprty.

    generateFile

    When this option is used, the data selector functionality from the GCL is used to generate a file (HTML/PDF). The user is then first shown a preview of this, and then it can be sent by email. Variables {selected_link_id} and {selected_id} contain comma separated of the ids of the selected items when generateFile is used from a grid.

    You can enter the following properties to set up the generation of the file:

    Property Mandatory Explanation
    queryId yes, or dataSelectorId Enter here the ID of the query stored in wiser_query that serves as the data source for the data to be generated.
    dataSelectorId yes, or queryId D of the stored data selector. This is the ID from the table wiser_data_selector.
    contentItemId yes The ID of the Wiser item that contains the template (HTML) for the file to be generated. A small example of such a template is this:
    {repeat} <!-- voor het genereren van meerdere documenten -->
    Field value: {fieldname}<br> <!-- for a fieldname from a query or dataselector -->
    [if({fieldvalue}!)]{fieldvalue}[else]empty[endif]
    {repeat:subobject} <!-- for example a invoicerule in an invoice -->
    amount: {subobject.subobjectfieldname}<br>
    {/repeat:subobject}
    {/repeat} <!-- einde repeat van het document -->
    contentPropertyName no The property_name of the field that contains the HTML for the file to be generated.
    pdfBackgroundPropertyName no The property_name of the field where an image can be added to be used as background in generated PDF files. This field must be of type Image-upload.
    pdfDocumentOptionsPropertyName no The property_name of the field where options can be set for generating the PDF. This can contain a value for example:
    De property_name van het veld waar de opties ingesteld kunnen worden voor het genereren van de PDF. Daar kan een waarde in staan zoals:
    HtmlViewerWidth:768;
    BottomMargin:0;
    LeftMargin:0;
    RightMargin:0;
    TopMargin:0;
    TopSpacing:100;
    BottomSpacing:50;
    LiveUrlsEnabled:true;
    AvoidTextBreak:true
    NOTE: the above values should be on 1 line
    pdfHeaderPropertyName no The property_name of the field that contains the HTML for the header. Used only when generating a PDF.
    pdfFooterPropertyName no The property_name of the field that contains the HTML for the footer. Only used when generating a PDF.
    pdfFilename no The filename of the PDF that can be generated using the "Save as PDF" button. As a variable {itemId} can be used in this filename.
    createSeparatePdfForEachSelectedItem no If multiple lines are selected in a grid, this option can be used to determine whether those lines should be merged into 1 PDF, or whether a separate PDF should be created for each line.
    disableHtmlEditor no Set this value to true if users are not allowed to make changes to the HTML used here.
    emailDataQueryId no Here you can enter an ID of a query from the table wiser_query which then returns default values for sending an e-mail. More information in the documentation below this table.
    executeQueryAfterEmail no Here an ID of a query from the table wiser_query can be filled in, this query is then executed after the user has successfully sent an e-mail via the generateFile screen.
    emailDefaultAttachmentsPropertyName no The property_name of the field containing the default attachments to be sent with the email, this must be a field of type 'File-upload'

    Sending email containing the generated document

    After generating the file, you also have the option of sending an e-mail with the generated file as an attachment. You will then get a popup with all the fields for sending an e-mail, for example recipient and subject. These fields can also be prefilled automatically with a query. To do this, you can fill the option emailDataQueryId with an ID of a query in the table wiser_query. That query should then return a result with the columns below:

    • senderName
    • senderEmail
    • receiverName
    • receiverEmail
    • cc
    • bcc
    • subject
    • body
    • attachmentFileName

    In that query, you can also use variables. The variables you can use are all the values of the userParameters and the following fixed variables:

    • itemId: The ID of the opened item.
    • itemLinkId: The ID of a link. For example, if the item in question was opened via a sub-entities grid, that is the ID of that link.
    • itemTitle: The title of the opened item.
    • encryptedId: The encrypted ID of the opened item.
    • environment: The published environment of the opened item.
    • entityType: The name of the entity of the opened item.
    • userId: The ID of the user logged into Wiser.
    • username: The name of the logged-in user in Wiser.
    • userEmailAddress: The email address of the logged-in user. This is the email address from the email address field of the corresponding WiserUser item.
    • userType: The type of the logged-in user. This is the value from the usertype column of the easy_users table in Wiser's database.

    The values the query then returns for these columns are populated in the corresponding fields for sending the email.

    Sample query:

    SELECT
        'Companyname' AS senderName,
        '[email protected]' AS senderEmail,
        'Bill Gates' AS receiverName,
        '[email protected]' AS receiverEmail,
        '[email protected]' AS cc,
        '[email protected]' AS bcc,
        'This is a test - {fieldname} - {itemId} - {itemTitle}' AS subject,
        '<p>Dear Mr/Mrs,</p><p>This is a test</p>' AS body,
        'Attachment_{itemId}.pdf' AS attachmentFileName;

    actionConfirmDialog

    This action opens a confirm dialog. If the user selects to continue the action will be continued. If the user selects to cancel the action will be aborted.

    You can set the following properties here:

    • title: The title of the confirm dialog. If none is entered the default "Doorgaan" will be used.
    • text: The text of the confirm dialog. If none is entered the default "Wilt u doorgaan met de actie?" will be used.

    mergeFiles

    Use this action to merge PDF files of various sources and offer the merged file as a single download.

    You can use this function in a stand-alone button or in a grid and select lines of files you want to merge. If you use this in a grid, the columns encrypted_id and entity_type must be available in the grid.

    Options you can set for this action:

    Property Mandatory Explanation
    propertyNames yes A comma-separated list for the property names of the files you want to merge
    queryId no The query to be executed to get the files you want to merge. If a query ID is available, the query will be executed and takes precedence over any lines in a grid that may be selected. The query must return the columns id (which contains the encrypted item_id) and propertynames (which contains a comma-separated list of the property names of the files that must be merged)
    entityType no Optional entityType to make sure only files of a certain entity are merged. But mandatory if the entity is stored in separate tables
    fileName no Optional filename of the file that is offered as download. Defaults to mergedpdf.pdf
    fileSelection no Optional can be used to determine which file should be selected if an item has multiple. Possible values are Newest and Oldest. By default no guarantee is given which file gets used.

    The UserParameter object

    The following describes which properties can be set for a UserParameter for an action. Multiple parameters can be set per action.

    Property Mandatory Explanation
    name yes The name of the parameter. This name can be used in the URL of certain actions, or you can use it as a variable in queries, for example.
    question no The text that will appear above the input field for that parameter. Question may be left blank, then the default text will be Enter a value for '${parameter.name}':.
    fieldType no By default, a simple text field is displayed but you can also use one of these alternatives for input:
  • datetime: A field requiring the user to enter a date and time.
  • date: A field for the user to enter a date.
  • time: A field for the user to enter a time.
  • number: A field for the user to enter a number.
  • comboBox: A selection field with values from which the user must select or enter a choice.
  • dropDownList: The same as comboBox, but in this the user cannot type a value themselves but can only select an existing value.
  • multiSelect: The same as dropDownList, but it allows multiple values to be selected.
  • grid: A table in which the user can filter and from which 1 row can be selected.
  • multiLine: A text field in which multiple lines are possible.
  • fileUpload: A field where the user can upload a file. This file is then added to wiser_itemfile at the itemLinkId or itemId of the opened/selected item. The user parameters will then include the ID of the line in wiser_itemfile, so you can run an additional query to move the file or do something else with it if necessary.
  • value no Allows you to enter a default value.

    For date/time fields, you can enter the text NOW() if you want to preselect the current date and/or time in the field.
    defaultValueQueryId no Here an ID of a query from wiser_query can be entered. This query then determines the value to be filled by default in this user parameter. This query should then return 1 row with the column value and that will be the default value. All other rows/columns of that query will be ignored.

    In this query all values of the opened or selected item (in case of a grid) can be used if needed.

    If this query returns no result, the value of the property value is used as the default value, provided it is filled.
    format no Allows you to determine the format of the value that will eventually be passed to the action. This allows you, for example, to convert entered dates/times to a particular format as you need it in a query. For dates, you can use these formats: Luxon documentation

    Specific settings by field type for a user parameter

    number

    For number fields, you can also use all the options of that field type.

    ComboBox, dropDownList and multiSelect

    For parameters of type comboBox, dropDownList and multiSelect, you can use the following additional options:

    Property Mandatory Explanation
    dataTextField yes The property that contains the visual value (such as the name of an item).
    dataValueField yes The property that contains the value returned to the action as a response (such as the ID of an item).
    dataSource no This allows you to determine which data should be used/displayed in the combobox. This can put an array of objects (where the properties must match the values of dataTextField and dataValueField. You can also use all options of a kendo dataSource here. This property is ignored if you have entered a queryId.

    Finally, you can also enter the value wiserUsers here, then you will get a list of all users of the given client who can log into Wiser.
    queryId no Enter here the ID of a query from the table wiser_query. This query will then be executed and that data will be used in the combo box. Note that the columns in your query must match the values of dataTextField and dataValueField.

    If this query is used to determine the contentItemId, it must also contain the encrypted version of itemId. For example: i.id AS encryptedId_encrypt_withdate
    userTypes no This option is only applicable if you have entered the value wiserUsers at dataSource. This is an array of one or more user types that you want to show in the list. If you do not enter anything here, all users will be shown.

    Grids

    For grid type parameters, you can use the following additional options:

    Property Mandatory Explanation
    customQuery no If you want to use a custom query for the grid, enter the value true here. Note that you must then also enter a queryId and countQueryId.
    queryId no the table wiser_query here. The result of this query is then used in the grid. You can then use the same settings here as you can find in the chapter on grids.
    countQueryId no If you want to use a custom query for the grid, it is recommended to also create a query that counts the total number of results. You can then enter the ID of that query here. This is necessary for proper paging. For more information see the chapter on grids.
    entityType no This is required when you do not use a custom query. Enter here the name of the entity of the items you want to display. For more information see the chapter on grids.
    selectable no This allows you to specify whether lines should also be selectable by clicking on them and whether you should then be able to select multiple lines (with CTRL/Shift). If only one line may be selected, enter the value row here, if multiple lines, enter the value multiple, row.
    checkboxes no Set this to false to disable checkboxes. Please do this only if the selectable option is set to true, otherwise a user cannot select anything.
    gridHeight no Enter the height of the grid in pixels here (as a number, e.g. 800). Default is 600.
    pageSize no Determines how many lines are displayed per page. Default is 10.
    columns no Determines columns to be shown. See the chapter on grids for more information.
    allowMultipleRows no By default, only 1 line can be selected in a grid. If this option is set to true, multiple lines can be selected. Eventually you will get a string with comma separated IDs as a result.

    File upload

    For parameters of type fileUpload, you can use the following additional options:

    Property Mandatory Explanation
    propertyName yes The value to be entered in the property_name column of the wiser_itemfile table when uploading the file.

    Full example of an action button with multiple actions:

    {
        "text": "Test button",
        "icon": "sln",
        "actions": [
            {
                "type": "executeQuery",
                "queryId": 2,
                "userParameters": [
                    {
                        "name": "invoicenumber",
                        "question": "What invoicedate do you want?",
                        "fieldType": "datetime",
                        "defaultValue": "NOW()"
                    },
                    {
                        "name": "user",
                        "question": "CHoose a user",
                        "fieldType": "combobox",
                        "dataSource": "wiserUsers",
                        "userTypes": ["FinanceUser"]
                    },
                    {
                        "name": "selected_id",
                        "question": "Select an item from the grid",
                        "fieldType": "grid",
                        "customQuery": true,
                        "queryId": 54,
                        "countQueryId": 55 
                    }
                ]
            },
            {
                "type": "openWindow",
                "itemId": "{itemId}"
            },
            {
                "type": "openUrl",
                "url": "https://url.com/?id={itemId}&title={itemTitle}&entityType={entityType}"
            },
            {
                "type": "generateFile",
                "dataSelectorId": 17,
                "contentPropertyName": "html_template",
                "contentItemId": 959335,
                "itemId": "{itemId}",
                "userParameters": [
                    {
                        "name": "client",
                        "question": "Select client",
                        "fieldType": "combobox",
                        "dataTextField": "text",
                        "dataValueField": "id",
                        "queryId": 12,
                        "value": 5561
                    }
                ]
            }
        ]
    }
    ⚠️ **GitHub.com Fallback** ⚠️