Script to run before the view is created.

HI, thanks.
I have a special requirement.
We created a custom module from opportunities, named bookings and a MasterData Module to keep record for the booking id, this number must increment for any new booking record, which it does for now.
But what I need, is that this number appears when creating a new record.
I already tried on creating a script in js, on creating the view, (extendsFrom: 'CreateView') but it seems it runs globally every time a view is created, it's very sensitive a minimal error will block the whole instance. I feel sorry everytime we required sugar support to helps us initialize the instance again.
I was wondering if there's a better place to implement this script, a logic hook or something like that, 
Thanks again.
Parents Reply Children
  • If I understand you correctly, you are looking for is an integer field that auto-increments for each new record.

    I have a custom module called wcont_Contracts which has a Contract Number field that is populated by the system as an auto increment number.

    The Contract Number is an Integer, Required, Read-Only field with auto_increment set to true.

    In the vardef of my field is as follows:

      'contract_number' =>
      array (
        'type'=>'int',
        'required' => true,
        'name' => 'contract_number',
        'vname' => 'LBL_CONTRACT_NUMBER',
        'readonly' => true,
        'len' => '11',
        'required' => true,
        'auto_increment' => true,
        'unified_search' => true,
        'full_text_search' =>
        array (
          'boost' => '3',
          'enabled' => true,
        ),
        'comment' => 'Visual unique identifier',
        'duplicate_merge' => 'disabled',
        'disable_num_format' => '1',
        'duplicate_on_record_copy' => 'no',
        'audited' => false,
        'massupdate' => false,
        'merge_filter' => 'disabled',
        'calculated' => false,
        'enable_range_search' => false,
        'min' => false,
        'max' => false,
      ),

    Then on the database I altered the field to be an auto-increment and start the numbers from 10000

    ALTER TABLE `wcont_contracts`
    CHANGE COLUMN `contract_number` `contract_number` INT(11) NOT NULL AUTO_INCREMENT, ADD INDEX `contract_number` (`contract_number`);
    alter table wcont_contracts AUTO_INCREMENT = 10000;

    You won't see the number in the record until after you Save, but it is created and entered for you.

    Hope this helps,
    FrancescaS

  • Thank you Andre, I'm sorry I didn't express myself quite enough.
    What I'm trying to do is. For example when a person let's say a receptionist, introduce and create new booking for a guest. I need display the next booking number, this is a autoincremental number, that I hold on the MasterData module, it increments, every time  a record is saved. (example 100,101,102). I have no problem with this.
    But what i need, is to display this number when the user create a new record. I already defined the variable and the field.
    I don't know how to auto fill this field, with this number. When the view is created for the new record.
    I tried to create a script for that, extending "CreateView", but it seems it affects all the views on the instance, even if the script is copied and defined only for this module. It seems to affects all the views on the instances, and it's very sensitive, any error, will complety block the whole instance.
    I tried also to implement a Logic Hook, but it seems there is not anything like "onCreate" event, only "beforeSave, afterSave".
    I hope you can understand  what I'm trying to do.
    I really apppreciate you help.
    Greetings.