Use a server script to manually trigger a playbook.

Trigger Playbook function

Manually trigger a Playbook using a server script function with the following code:
sn_playbook.PlaybookExperience.triggerPlaybook('<scoped name>',parentRecord);
Replace <scoped name> with the scoped name of your playbook. You can find the scoped name by locating the process definition in the sys_pd_process_definition table and copying the name and application scope fields. Replace parentRecord with the input/parent record you want to run the process on.

The server script throws an exception on failure. You can add an info message when successful and an error message on failure.

Helper functions

Use the following scriptable function to determine if a Playbook is already running on a record before displaying a UI action or declarative action to trigger it.
sn_playbook.PlaybookExperience.parentRecordContainsPlaybook(parentRecord, '<scoped name>')
To view every playbook running on a given parent record use the following code:
sn_playbook.PlaybookExperience.getPlaybooksForParentRecord(parentRecord)
This information can be used to control when to show a trigger playbook action such as a UI action.

The following section is an example of how to use the trigger playbook function to create an Add Playbook button.

Create an Add Playbook UI Action

Create an Add Playbook UI Action in workspace.

Before you begin

Role required: workspace_admin

Procedure

  1. Navigate to All > System Definitions > UI Actions.
  2. Click New.
  3. In the form, fill in the fields.
    Note: Other fields than those in the following table appear in the form but they do not function in workspaces. For more information on each field on the UI actions form, see Set up custom UI actions in legacy workspace.
  4. To create a server-side script that implements the add playbook action, enter the script in the Script field.
    try{
    	current.update();
    	sn_playbook.PlaybookExperience.triggerPlaybook('sn_pad_demo.playbook_onboarding_demo',current);
    	gs.addInfoMessage(gs.getMessage("Onboarding Playbook added to Interaction."));
    } catch(e){
    		gs.addErrorMessage(e.getMessage());
    }

    The system ignores any client scripts that are included in this field. You can only use the workspace client script field for client scripts. Replace sn_pad_demo.playbook_onboarding_demo with the scoped name of your playbook. You can find the scoped name by locating the process definition in the sys_pd_process_definition table and copying the name and application scope fields.

  5. In the Workspace tab, select: Workspace Form Button to make the add playbook button appear on the line of UI actions, or Workspace Form Menu to make it appear as a list in the menu list.
  6. In the Workspace Client Script field, create a workspace-specific client script.
    Workspace has similar client scripting limitations as Service Portal. For example, to open a form by clicking it, you could add the following client script:
    function onClick(g_form) {
    
    }