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
  • It is not quite clear. Can you kindly better describe the requirement?

    A mockup is welcome.

    Regards

    André Lopes
    Lampada Global
    Skype: andre.lampada
  • 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

  • HI, Francesca, I really appreciate you help.

    I have created a module, called MasterData, in this module I keep this autoincremental number. I managed this way, for the case, if the client needs or wants to change current number. The client can change it directly in this module.
    But mi problem is that I need 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, so the person can see this number auto filled in the field.
    I increment this number with a Logic Hook, on "beforeSave" event.
    I tried to create a script for that, extending "CreateView", but it seems it affects all the views on the instance, even the script is copied and defined only for this module. And it's very sensitive any error, will block the whole instance.

    Thank you.

    Greetings.

Reply
  • HI, Francesca, I really appreciate you help.

    I have created a module, called MasterData, in this module I keep this autoincremental number. I managed this way, for the case, if the client needs or wants to change current number. The client can change it directly in this module.
    But mi problem is that I need 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, so the person can see this number auto filled in the field.
    I increment this number with a Logic Hook, on "beforeSave" event.
    I tried to create a script for that, extending "CreateView", but it seems it affects all the views on the instance, even the script is copied and defined only for this module. And it's very sensitive any error, will block the whole instance.

    Thank you.

    Greetings.

Children
No Data