Problem with autoincrement custom field

Hi to all, i create a custom field autoincrement in my Opportunity module. I made a php file in custom\extention\modules\opportunities\ext\vardefs\sugarfield_autoincrement.php

<?php

$dictionary["Opportunity"]["fields"]["id_offerta"] =array (
    "name" => "id_offerta",
    "vname" => "Id Offerta",
    "type" => "int",
    "massupdate" => 0,
    "comments" =>"",
    "help" => "",
    "importable" => "true",
    "duplicate_merge" => "disabled",
    "duplicate_merge_dom_value" => "0",
    "audited" => false,
    "reportable" => true,
    "calculated" => false,
    "auto_increment"=>true,
);

$dictionary["Opportunity"]["indices"]["id_offerta"] = array(
    "name" => "id_offerta",
    "type" => "unique",
    "fields" => array(
        "id_offerta"
    ),
);

?>

It works fine the first time, the quick repair goes till end withot error, but after that everytime i quick and repair i have this error:

Mon Feb 26 14:58:39 2018 [8556][1][FATAL] Executing repair query:  Query Failed:ALTER TABLE opportunities DROP CONSTRAINT id_offerta  ALTER TABLE opportunities ALTER COLUMN [id_offerta] int NOT NULL identity(1,1)::: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]Incorrect syntax near the keyword 'identity'.
Mon Feb 26 14:58:39 2018 [8556][1][FATAL] Exception handling in C:\SITI\crmdemo\include\MVC\Controller\SugarController.php:402
Mon Feb 26 14:58:39 2018 [8556][1][FATAL] Exception in Controller: Errore nel Database. Per dettagli si prega di fare riferimento al registro errori di SuiteCRM.
Mon Feb 26 14:58:39 2018 [8556][1][FATAL] backtrace:
#0 C:\SITI\crmdemo\include\database\DBManager.php(353): sugar_die('Errore nel Data...')
#1 C:\SITI\crmdemo\include\database\DBManager.php(328): DBManager->registerError('Executing repai...', 'Executing repai...', true)
#2 C:\SITI\crmdemo\include\database\SqlsrvManager.php(227): DBManager->checkError('Executing repai...', true)
#3 C:\SITI\crmdemo\modules\Administration\repairDatabase.php(90): SqlsrvManager->query('ALTER TABLE opp...', true, 'Executing repai...')
#4 C:\SITI\crmdemo\include\MVC\View\SugarView.php(791): include_once('C:\\SITI\\crmdemo...')
#5 C:\SITI\crmdemo\include\MVC\View\views\view.classic.php(74): SugarView->includeClassicFile('modules/Adminis...')
#6 C:\SITI\crmdemo\include\MVC\View\SugarView.php(199): ViewClassic->display()
#7 C:\SITI\crmdemo\include\MVC\Controller\SugarController.php(432): SugarView->process()
#8 C:\SITI\crmdemo\include\MVC\Controller\SugarController.php(375): SugarController->processView()
#9 C:\SITI\crmdemo\include\MVC\SugarApplication.php(105): SugarController->execute()
#10 C:\SITI\crmdemo\index.php(52): SugarApplication->execute()
#11 {main}

And i don’t really know how to fix that. Someone could me help?

thanks to all

Hi,

looks like mssql does not support alter column identity, but can be done though ssms

https://blog.sqlauthority.com/2009/05/03/sql-server-add-or-remove-identity-property-on-column/

Julien

1 Like

The problem is different, when i try to repair the first time, the code will put identity and works, but when he try to alter table, give me the error, and i don’t know how to fix this