Creating a logic hook to update the 'assigned_to' field to current_user

Hi,

When copying and saving a quote, the products show the assigned to as the original user and not the user that copied the quote.

I'm new to Sugar CRM and am trying to create a logic hook to update the assigned_to field to the current user for each product line in a quote when saving the record.

This is my attempt but did not work, any suggestions would be welcome.

Thank You,

<?php

$dependencies['products']['populate_assigned_user'] = array(
'hooks' => array("edit"), //not including save so that the value isn't stored in the DB
'trigger' => 'greaterThan(strlen(related($quotes,"assigned_user_name")),0)', //Optional, the trigger for the dependency. Defaults to 'true'.
'onload' => 'true', //Whether or not to trigger the dependencies when the page is loaded
'actions' => array(
array(
'name' => 'SetValue',
'params' => array(
'target' => 'assigned_user_id',
'value' => 'related($quotes,"assigned_user_id")'

)
),
array(
'name' => 'SetValue',
'params' => array(
'target' => 'assigned_user_name',
'value' => 'related($quotes,"assigned_user_name")'

)
)
)
);

Parents Reply Children
  • From the code previously provided

    <?php
    
    $dependencies['Products']['populate_assigned_user'] = array(
        'hooks' => ['all'],
        'trigger' => 'greaterThan(strlen(related($quotes,"assigned_user_name")),0)', 
        'onload' => 'true', 
        'actions' => array(
             array(
                    'name' => 'SetValue',
                    'params' => array(
                        'target' => 'assigned_user_id',
                        'value' => 'related($quotes,"modified_user_id")'
                    )
            ),
            array(
                    'name' => 'SetValue',
                    'params' => array(
                        'target' => 'assigned_user_name',
                        'value' => 'related($quotes,"modified_by_name")'
                    )
                )       
                
        )
    );
    ?>

    André Lopes
    Lampada Global
    Skype: andre.lampada