runAction()

The runAction() function (client-side) calls a server-side or client-side action.

Syntax

Use these syntax formats for the runAction() function:

  • To pass an object parameter:

                    runAction({
        code: 'ACTION_CODE',
        async: true | false
    }).done(callback); 
    
                  
  • To pass the server-side action code as string parameter (only works in asynchronous mode):

                    runAction('ACTION_CODE').done(callback); 
    
                  

Return Value

The runAction() function returns a promise that resolves to:

  • An object for server-side actions.

  • undefined for client-side actions.

Parameters

Note:

The action code is required.

When passing an object to the runAction() function, the object accepts the following properties:

  • code - Specifies the code of the action to call as a string. You can find the code in the Code field on the action record.

  • async - Determines whether the action call is synchronous or asynchronous. This property is true by default.

Examples

The following examples show how to use the runAction() function.

Calling a Server-Side Action

In this example, runAction() calls a server-side action in a loop until all records are created.

              // Client-side action
(async function() {
    scratchpad.output = [];
    scratchpad.records = getValue('DATA', 'RECORDS'); // Array of records to be created
    scratchpad.index = 0;
    let count = scratchpad.records.length;
    do {
        await runAction('CREATE_RECORDS');
    } while (scratchpad.index < count);
    console.log('FINISH', scratchpad.output);
})(); 

            

Related Topics

General Notices