Issue with Custom Button in Contacts Module DetailView

I have been trying to add a custom button in the DetailView of the Contacts module. The purpose of this button is to trigger a specific action when clicked.
I’ve added the custom button to the detailviewdefs.php file for the Contacts module. The custom button is defined in recordActions and is supposed to invoke a custom service for further processing.

'recordActions' => [
                 'actions' => [
                     'print-as-pdf' => [
                         'key' => 'print-as-pdf',
                         'labelKey' => 'LBL_PRINT_AS_PDF',
                         'asyncProcess' => true,
                         'modes' => ['detail'],
                         'acl' => ['view'],
                         'aclModule' => 'AOS_PDF_Templates',
                         'params' => [
                             'selectModal' => [
                                 'module' => 'AOS_PDF_Templates'
                             ]
                         ]
                     ]  ,                        
               
               'custom-button-action' => [
                 'key' => 'custom-button-action',
                 'labelKey' => 'LBL_CUSTOM_BUTTON',
                 'asyncProcess' => true,
                 'modes' => ['detail'],
                 'acl' => ['view'],
                 'aclModule' => 'Contacts',
                 'service' => 'CustomButtonHandler',
                
             ] ,
                 ]
             ],

I’ve also created the corresponding service class in the location core/backend/Process/Service/RecordActions/CustomButtonHandler.php
[ have also tried the location extensions/defaultExt/backend/modules/Contacts/Services/CustomButtonHandler.php]

When I click the custom button in the Contacts DetailView, I receive an “Unexpected error when calling action” message.
I would greatly appreciate any assistance, suggestions, or insights from the community to help me resolve this issue and get the custom button functioning correctly.

Thank you in advance for your support!

Did you clear the Symfony cache between attempts?

Try asking the Symfony console for help with

bin/console debug:container CustomButtonHandler

(you can use full name of your class, or a partial name and it will match any similar classes).

1 Like

Hey @Anitha you’re in luck i think i can help you as i’ve been working with buttons and processes for the past few days ! first of, i would advise using firefox and turning the env of your project into dev, with debug true
APP_ENV=dev

APP_DEBUG=true

the effect will be that in your firefox network tab, once you click on your button, you will see the detail of the error instead of the generic internal server error

There are a lot of possible causes for the error, but something common is for instance is a mismatch between the id/name of the process and what suitecrm has. For instance, even though you have print-as-pdf, maybe suitecrm has something like record-print-as-pdf, and if that’s the case it will tell you inside the error thanks to being in dev mode.

If that’s the case, simply adjust the id/name in the process and then you will manage to get in the run function of the process. From there, you can use xdebug until it works.

Feel free to contact me if you need anything !

1 Like

Thanks for your prompt response!Thank you for your prompt response. With your guidance, I successfully identified and adjusted the process ID/name mismatch.

@pgr @myddleware As I am relatively new to SuiteCRM, I now seek assistance in adding actual buttons against each record row in the list view in SuiteCRM 8. Your support will be highly appreciated. Thanks in advance!

As I am relatively new to SuiteCRM, I now seek assistance in adding actual buttons against each record row in the list view in SuiteCRM 8. Your support will be highly appreciated. Thanks in advance!

Thanks for your support!

1 Like

@Anitha Hi Anitha, glad the process worked ! Unfortunately I’m not part of the suitecrm team and since I haven’t tried to add something like this so far so i wouldn’t know what’s the best approach. I advise you to make a new post for this specific issue, I’m sure someone on the team will be able to help you.

Best of luck in your projects !

1 Like

HI guys, I can’t even get the button to show, what are the steps to get the button to show up in the module? I’m trying to put one in ‘Accounts’ to open a popup that will bring up my Nextcloud instance and attach a file to the record via a link but as mentioned, can’ t get the button to show,. I’m trying the ‘Editview’, here’s my code:

array(
                    'customCode' => '
                        <button id="nextcloud_attach_button" type="button" class="btn btn-primary">Attach File/Folder from Nextcloud</button>
                        <script>
                            $(document).ready(function() {
                                $("#nextcloud_attach_button").click(function() {
                                    window.open("/custom/nextcloud_picker.php", "Nextcloud File Picker", "width=800,height=600");
                                });
                            });
                        </script>',
                    'type' => 'button',
                    'name' => 'nextcloud_attach_button',
                    'label' => 'Attach File/Folder from Nextcloud',
                    'showOn' => 'view',
                    'acl_action' => 'view',
                    'css_class' => 'btn-primary',
                    'icon' => 'fa-cloud',
                    'sequence' => 5,
                ),
            ),

Hi @xxBenjamin_Doverxx
This video might solve your issue.
How to add Module-Specific Record Actions on Suite 8.