can integers field be auto incremented through studio
can integers field be auto incremented through studio
I solved it using a LogicHook that called a function to autoInc for me. It looks like this
First, in Studio I added a new integer field to the ProjectTask module called 'project_task_id'
Then, in custom/modules/ProjectTask/logic_hooks.php I added the following:
$hook_version = 1;
$hook_array = Array();
// position, file, function
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'auto_inc_pt', 'custom/include/autoIncProjectTaskId.php','IncProjectTaskId', 'updateProjectTask');
Finally, I created a file 'custom/include/autoIncProjectTaskId.php' that looks like:
<?php
class IncProjectTaskId {
function updateProjectTask(&$bean, $event, $arguments)
{
if ( !isset( $bean->project_task_id ) || '' == $bean->project_task_id )
{
$query = "SELECT MAX(project_task_id) AS max_project_task_id FROM project_task pt ";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc( $results );
$pt_id = isset( $row )
? $row['max_project_task_id'] + 1
: 1 ;
//Change project_task_id value on Project Task
$bean->project_task_id = $pt_id;
}
}
}
Let me know if this helps.
Thanks Tim Turnquist!
Just used this method for getting auto increment numbers for a custom module.
Comined a different way, to at once concatenate to the name field to create unique name to a module (which is not create from "case" template!
<?php
//custom/modules/FOGL_JARMU_VONATK_FOGL/dftGenerateAutoIncNumber.php
class dftGenerate {
function dftGenerateAutoIncNumber(&$bean, $event, $arguments)
{
if($bean->name == '0'){
$Vonatkartya = $bean-> tech_vonatkartya_name_c;
if ( !isset( $bean->case_number_c ) || '' == $bean->case_number_c )
{
$query = "SELECT MAX(case_number_c) AS max_case_number_c FROM fogl_jarmu_vonatk_fogl_cstm vf ";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc( $results );
$vf_id = isset( $row )
? $row['max_case_number_c'] + 1
: 1 ;
//Change case_number_c value on Vonatkartya foglalo
//Create unique name.
$bean->case_number_c = $vf_id;
}
$ID_code ="{$Vonatkartya} foglalás [$vf_id]";
$bean ->name = $ID_code;
}
}
}
Thanks Tim Turnquist!
Just used this method for getting auto increment numbers for a custom module.
Comined a different way, to at once concatenate to the name field to create unique name to a module (which is not create from "case" template!
<?php
//custom/modules/FOGL_JARMU_VONATK_FOGL/dftGenerateAutoIncNumber.php
class dftGenerate {
function dftGenerateAutoIncNumber(&$bean, $event, $arguments)
{
if($bean->name == '0'){
$Vonatkartya = $bean-> tech_vonatkartya_name_c;
if ( !isset( $bean->case_number_c ) || '' == $bean->case_number_c )
{
$query = "SELECT MAX(case_number_c) AS max_case_number_c FROM fogl_jarmu_vonatk_fogl_cstm vf ";
$results = $bean->db->query($query, true);
$row = $bean->db->fetchByAssoc( $results );
$vf_id = isset( $row )
? $row['max_case_number_c'] + 1
: 1 ;
//Change case_number_c value on Vonatkartya foglalo
//Create unique name.
$bean->case_number_c = $vf_id;
}
$ID_code ="{$Vonatkartya} foglalás [$vf_id]";
$bean ->name = $ID_code;
}
}
}