Skip to content

Dispatch bucket

Placing related dispatches into dispatch bucket. If you want to place related dispatches into a bucket that can be easily retrieved later, you can use dispatch buckets.

Examples

Placing dispatches into a dispatch applicants bucket. In this example, ownerId is the dispatch that the applicants are applying to. The handle of the bucket is applicants as we can have multiple handles, e.g. approved, declined, etc.

-- Lua Code
-- parent dispatch (aka owner)
-- bucket name: applicant
mock("dispatchId", "65dd39c8-4e49-4aa4-be20-6f72a5d9375a")
local dispatchId = param("dispatchId")
local bucketName = "applicants"
local dispatch = first(core.QueryDispatch("id:"..dispatchId))

if dispatch ~= nil and dispatch.data.campaignId ~= nil then
    log.pairs(dispatch.data)

    local campaignId = dispatch.data.campaignId

    local campaign = first(core.QueryDispatch("id:"..campaignId))

    if campaign ~= nil then
        local applicants = (campaign.data.applicants or 0) + 1

        -- update applicants count
        local data = campaign.data
        data.applicants = applicants

        core.UpdateDispatchData({
            dispatchId=campaignId,
            trackerId=campaign.trackerId,
            data=data
        })

        -- placing the applicants into the bucket
        core.AddDispatchBucketDispatch({
            dispatchId=dispatchId,
            ownerId=campaignId,
            handle=bucketName
        })

        -- add key to the applicant dispatch so that we can search
        core.ApplyDispatchKeys(
            dispatchId,
            {
                {
                    name="campaign",
                    value=campaignId
                }
            }
        )
    end
end