File download from record action

Hi all,

I’m trying to do the following:
in the detail /edit view of an Account, provide a button in the record’s action dropdown that

  • let’s you select linked quotes in a modal
  • creates a file (e.g. pdf) for that quote & account and sends it (download)

I’ve managed the first part following this tutorial:

The problem is though, that this is an async action. I can think of two options to solve that, and would appreciate hints on how to do either of them (or even another solution).

Option 1: return a url in the return value and add some javascript to redirect to it. I know how to add the url in the response, but how and where would I add the javascript? And would that target URL be a custom entry point?

Option 2: call a custom entrypoint, i.e. redirect to it directly from the action dropdown’s button. Unfortunately, I found no tutorial on how to do that. I’ve tried the following, with keys like uri/url/link…, but none seems to work. btw…where are all the possible keys documented?

$recordActions['create-pdf'] = [
        //'key' => 'account-create-pdf',
		'uri' => 'index.php?entryPoint=MyEntryPoint'
        'labelKey' => 'LBL_CREATE_PDF', 
        'modes' => ['detail', 'edit'],
        'params' => [
            // Allow selecting a record from a modal before running action
            'selectModal' => [
                'module' => 'AOS_Quotes'
            ]
        ]
    ];

Thanks!

BR,
Chris

In the response data sent from the backend as a return to the request, you can specify a handler that instructs the front-end to do something extra.

Currently these handlers can be ‘redirect’, ‘audit’, ‘export’, and ‘changelog’, see

core/app/core/src/lib/services/process/processes/async-action/actions

Have a look at the core function called PrintAsPdf, it’s very similar to what you’re trying to do

core/backend/Process/Service/RecordActions/PrintAsPdfAction.php

2 Likes

For calling an entrypoint please refer this file
{ROOT}core\backend\Process\Service\RecordActions\PrintAsPdfAction.php

and method getDownloadData()

For adding a button and selecting records , refer this file
{ROOT}\public\legacy\custom\modules\Accounts\metadata\detailviewdefs.php

‘key’ and ‘labelKey’ keys are used to display a button in the detail view button list actions.

and refer record action definition to set aclModule=>‘AOS_Quotes’ and selectModel ‘module’=>‘AOS_Quotes’ as show below

    'recordActions' => [
          'actions' => [
              'print-as-pdf' => [
                  'key' => 'print-as-pdf',
                  'labelKey' => 'LBL_PRINT_AS_PDF',
                  'asyncProcess' => true,
                  'modes' => ['detail'],
                  'acl' => ['view'],
                  'aclModule' => 'AOS_Quotes',
                  'params' => [
                      'selectModal' => [
                          'module' => 'AOS_Quotes'
                      ]
                  ]
              ],
1 Like