Skip to content
Content only available in english

core.addCustomBatchAction

Allows addition of custom batch operations. With this customization, you can implement actions that run on multiple selected instances (in a listing).

Usage:

javascript
core.addCustomBatchAction({
    key: `<generic-key-for-action>`,
    label: "<label-of-the-button>",
    group: "<the-group-button-name>",
    isAllowed: function(definitionM){
        ...
        return true or false
    },
    execute: function(definitionId, indexedInstancesM, ctx) {
        ...
    },
    executeOnQuery: async function(definitionId, query, ctx) {
        ...
    }
})

Arguments:

ArgumentDescriptionRequired
keyA key that serves as an identifier for that action.YES
labelName of the action. Also the name that appears in the action button.YES
groupName of the group we wish to show this action under. If multiple actions, with different names, share the same group, they will appear as children of said group.YES
isAllowedFunction responsible for making sure if running this action is allowed for a given definition.YES
executeFunction responsible for executing the actual batch action we wish to run on our selected instances.
executeOnQuerySame goal as execute, but it is ran in cases when all the selected instances are NOT shown on a listing (meaning part of them are in the next page of the listing for example) - i.e when all of the selected instances are not visible in the current page.

isAllowed function arguments:

ArgumentDescription
definitionMInformation regarding the current (seen) definition.

execute function arguments:

ArgumentDescription
definitionIdID of the current definition.
indexedInstancesMList with the selected instances.
{columnLabels, presenter}Respectively, column names and object responsible for showing listing.

executeOnQuery function arguments:

ArgumentDescription
definitionMInformation regarding the current (seen) definition.
queryThe query that was used to selected / view all the selected instances.
{columnLabels, presenter}Respectively, column names and object responsible for showing listing.

Example:

For this example, we programmed a custom batch action that sets the set the selected Tickets' state to 'Done'.

javascript
cob.custom.customize.push(function (core, utils, ui) {
  const DEFINITION = "Tickets";

  core.addCustomBatchAction({
    key: `tickets-set-done`, 
    label: "Mark as Done", 
    group: "Ticket Operations",
    isAllowed: function (definitionM) { 
			return definitionM['data']['name'] === DEFINITION 
    },
    execute: function (definitionId, indexedInstancesM, {columnLabels, presenter}) {
      indexedInstancesM.forEach(async (instance) => {
        if (instance['data']['state'][0] === "Open") {
          const updates = {
            "type": DEFINITION, "condition": `id:${instance['data']['instanceId']}`,
            "values": {
              "State": "Done"
            }
          }
          await axios.put("/recordm/recordm/instances/integration", updates)
        }
      })
      location.reload()
    },
    executeOnQuery: async function (definitionId, query, {columnLabels, presenter}) {
      return
    }
  })
});

screenshot_2024-02-27_at_15.44.28