Add custom button to Action in Detail view

I was trying to add a button from the actions dropdown in detail view. The button when clicked should change the account status field.

Here is the code I have added in suitecrm/custom/modules/Accounts/metadata/detailviewdefs.php but this is not changing the status field value. The Account page looks refreshed as it is going to the Home page and coming back to the same account page after clicking on the Button.

array (
            'customCode' => '<form><input type = "hidden" name ="isSaveAndNew" value = "false">
			                       <input type = "hidden" name ="status_c" value = "">
			                       <input type = "hidden" name ="isSaveFromDetailView" value = "true">
			                       <input title="Move to Next Status" class="button" 
                                         onClick="this.form.status_c.value=\'Pilot\';
                                                  this.form.action.value=\'Save\';
										          this.form.return_module.value=\'Accounts\';
                                                  this.form.return_action.value=\'DetailView\';
                                                  this.form.return_id.value=\'{$fields.id.value}\';
                                                  this.form.module.value=\'Accounts\';"
                                         name="move_to_next_status"  
                                         value="Move to Next Status"  
                                         type="submit"></form>',
          )

Where is your Code? Please share that

This is the code

anyone has a solution?

Are you using v7.x or v8.x?

1 Like

i am using v8.6 i am trying this way but i don’t know what is the problem

<?php

namespace App\Extension\defaultExt\modules\Leads\Services;

use ApiPlatform\Core\Exception\InvalidArgumentException;
use App\Module\Service\ModuleNameMapperInterface;
use App\Process\Entity\Process;
use App\Process\Service\ProcessHandlerInterface;

class AssignLeadAction implements ProcessHandlerInterface
{
    protected const MSG_OPTIONS_NOT_FOUND = 'Process options are not defined';
    protected const PROCESS_TYPE = 'record-assign-lead';

    /**
     * @var ModuleNameMapperInterface
     */
    private $moduleNameMapper;

    /**
     * MergeRecordsBulkAction constructor.
     * @param ModuleNameMapperInterface $moduleNameMapper
     */
    public function __construct(ModuleNameMapperInterface $moduleNameMapper)
    {
        $this->moduleNameMapper = $moduleNameMapper;
    }

    /**
     * @inheritDoc
     */
    public function getProcessType(): string
    {
        return self::PROCESS_TYPE;
    }

    /**
     * @inheritDoc
     */
    public function requiredAuthRole(): string
    {
        return 'ROLE_USER';
    }

    /**
     * @inheritDoc
     */
    public function getRequiredACLs(Process $process): array
    {
        $options = $process->getOptions();
        $module = $options['module'] ?? '';
        $id = $options['id'] ?? '';

        return [
            $module => [
                [
                    'action' => 'view',
                    'record' => $id
                ],
            ],
        ];

    }

    /**
     * @inheritDoc
     */
    public function configure(Process $process): void
    {
        //This process is synchronous
        //We aren't going to store a record on db
        //thus we will use process type as the id
        $process->setId(self::PROCESS_TYPE);
        $process->setAsync(false);
    }

    /**
     * @inheritDoc
     */
    public function validate(Process $process): void
    {
       
    }

    /**
     * @inheritDoc
     */
    public function run(Process $process)
    {
        $options = $process->getOptions();
       $leadid=$options['record']['attributes']['id'];
       $leadbean=BeanFactory::getBean('Leads',$leadid);

       $leadbean->status="Assigned";
        $responseData = [
            'handler' => 'redirect',
            'params' => [
                'route' => $options['module'] . '/convert-lead/' . $options['id'],
                'queryParams' => [
                ]
            ]
        ];
        $process->setStatus('success');
        $process->setMessages([]);
        $process->setData($responseData);
    }
}

this is my code

I think @Harshad could help you with it.

Make sure you have correct permissions and ownership to these files.

Answered in your another post: :white_check_mark: