diff --git a/packages/server/src/api/controllers/rowAction/run.ts b/packages/server/src/api/controllers/rowAction/run.ts index a1fa0cfe69..c4b6a276bf 100644 --- a/packages/server/src/api/controllers/rowAction/run.ts +++ b/packages/server/src/api/controllers/rowAction/run.ts @@ -2,13 +2,9 @@ import { RowActionTriggerRequest, Ctx } from "@budibase/types" import sdk from "../../../sdk" export async function run(ctx: Ctx) { - const { tableId } = ctx.params - const table = await sdk.tables.getTable(tableId) - if (!table) { - ctx.throw(404) - } - + const { tableId, actionId } = ctx.params const { rowId } = ctx.request.body - console.warn({ rowId }) + + await sdk.rowActions.run(tableId, actionId, rowId) ctx.status = 200 } diff --git a/packages/server/src/automations/triggers.ts b/packages/server/src/automations/triggers.ts index 99fc7f02f2..4cbde14c46 100644 --- a/packages/server/src/automations/triggers.ts +++ b/packages/server/src/automations/triggers.ts @@ -121,7 +121,7 @@ function rowPassesFilters(row: Row, filters: SearchFilters) { export async function externalTrigger( automation: Automation, - params: { fields: Record; timeout?: number }, + params: { fields: Record; timeout?: number; appId?: string }, { getResponses }: { getResponses?: boolean } = {} ): Promise { if (automation.disabled) { diff --git a/packages/server/src/sdk/app/rowActions.ts b/packages/server/src/sdk/app/rowActions.ts index e59337a7c9..9540198931 100644 --- a/packages/server/src/sdk/app/rowActions.ts +++ b/packages/server/src/sdk/app/rowActions.ts @@ -1,13 +1,15 @@ import { context, HTTPError, utils } from "@budibase/backend-core" -import { generateRowActionsID } from "../../db/utils" import { SEPARATOR, TableRowActions, VirtualDocumentType, } from "@budibase/types" +import { generateRowActionsID } from "../../db/utils" import automations from "./automations" import { definitions as TRIGGER_DEFINITIONS } from "../../automations/triggerInfo" +import * as triggers from "../../automations/triggers" +import sdk from ".." function ensureUniqueAndThrow( doc: TableRowActions, @@ -143,3 +145,25 @@ export async function remove(tableId: string, rowActionId: string) { const db = context.getAppDB() await db.put(actionsDoc) } + +export async function run(tableId: any, rowActionId: any, rowId: string) { + const table = await sdk.tables.getTable(tableId) + if (!table) { + throw new HTTPError("Table not found", 404) + } + + const { actions } = await get(tableId) + + const rowAction = actions[rowActionId] + if (!rowAction) { + throw new HTTPError("Row action not found", 404) + } + + const automation = await sdk.automations.get(rowAction.automationId) + + const row = await sdk.rows.find(tableId, rowId) + await triggers.externalTrigger(automation, { + fields: { row, table }, + appId: context.getAppId(), + }) +}