SuiteCRM ID FIeld

Hi there,

could please someone provide me code for an Id Field?

I am stuck at this Point:

te_lb_load_board_save.php


<?php

$hook_array['before_save'][] = Array(2, 'Custom Logic', 'custom/modules/te_lb_load_board/te_lb_load_board_save.php','te_lb_load_board_save', 'auto_increment');

?>

<?php

my_logichook.php


 if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');

     class {module}_Save
     {
          function auto_increment($bean, $event, $arguments)
          {
               if (!isset($bean->fetched_row['id'])) { // only for new records
                    $max_id = $GLOBALS['db']->getOne("select max(integer_field_c) from te_lb_load_board_cstm");
                    
                    if (empty($max_id)) {
                         $max_id = 1;
                    } else {
                         $max_id = $max_id+1;
                    }

                    $bean->integer_field_c = $max_id;
               }
          }
     }

?>

You’re stuck, but you didn’t say what happens? An error? Nothing? Is the function called at all?

Check this part

class {module}_Save

if you really have it like that, it can’t work, replace with the class name referenced in the hook definition.

Hi Pgr,

thank you for your help,
my class name should be “te_lb_load_board_save” in this case, am I right?

I guess so. Try it! :slight_smile:

1 Like

it works perfect, thank you a lot :woohoo: