Use Do()
to programmatically execute an action for the specified record(s) and/or user. This may be useful, in particular, in the following cases:
for executing nested actions (for example, for executing an action for records found within a Match records action);
for creating records in related objects (for example, an opportunity for a given contact);
for automatic creation of optimized routes (using a Visit planner action),
and many more.
When an action is executed, a nested context object is created at the current level of the execution context, and its key is returned by Do(), so you can retrieve data stored in the action's context using the GetC() function.
How to use
Use the function in any of the following ways:
Do(actionApiName, recordId[, userId])
Do(actionApiName, recordIds[, userId])
Do(actionApiName, record[, userId])
Do(actionApiName, records[, userId])
Input
actionApiName
: the API name of the action to be executed;
recordId
,recordIds
: a record ID or an array of record IDs for which to execute the action.
Maply will assume thatrecordId
belongs to the object selected in the properties of theactionApiName
action, sorecordId
/recordIds
can only be used with actions whose Objects property contains precisely one object; otherwise, you'll get the following errors:
if
actionApiName
action's Object property is empty:
Base object not specified for record ID ... . For actions without specified object, pass entire record as 2nd argument of Do() instead of record ID.
if
actionApiName
action's Object property contains multiple objects:
Ambiguous object for record ID ... . For actions applicable to multiple objects, pass entire record as 2nd argument of Do() instead of record ID.
record
,records
: a record or an array of records for which to execute the action.
A record here is a context object with at least 3 fields:
{id: ..., __objectApiName: ..., __sourceApiName: ...}
, here:
-id
is the ID of the record for which you're executing the action,
-__objectApiName
is the API name of its object,
-__sourceApiName
is the API name of the record's data source.
Example: if you want to execute a showMessage action for a Contact with the ID stored in the context variablerecordId
, you can formrecord
when callingDo()
like this:
Do('showMessage', {id: recordId, __objectApiName: 'Contact', __sourceApiName: 'HubSpot'})
The record
andrecords
context objects that are present in the execution context when a workflow or a button is invoked for one or multiple data records, already contain these 3 fields and thus can be passed toDo()
directly:Do('someAction', record)
.
Similarly, therecords
object created within the Match records action's context, which contain the found records, can also be passed toDo()
directly.
userId
(optional): the Mapsly user ID for which to execute the action, which is currently only supported when executing a Visit planner action. For example, to plan visits for the user who clicks the button, you may pass the current user's ID to Do() this way:Do(“plan_visits”, null, currentMapslyUser.userId.system)
Output
Context ID of the action that has been executed. You may use it as input for GetC(). Example of a Twig code that retrieves a myVar
key from the context of a myActionApiName
action executed for record ID record.id
:
{{ GetC("myVar", Do("myActionApiName", record.id)) }}
Examples
Do("createCheckInRecord", record.id)