Menu

Incrementing items/field from DB

2021-03-08
2021-03-09
  • Popa Silviu

    Popa Silviu - 2021-03-08

    Hello,

    i have a question/problem
    I have implemented in ITOP a field(ASC) that auto increment averytime when i create a server/pc/ etc.
    The ASC wanna to add manualy or to be automated in some casses.

    example: PC-01 have auto assigned ASC-01, but the next PC-02 i wanna to add manualy ASC-10 and the next one PC-03 should be auto assigned ASC-11.

    But in my casse is like that : PC-01 have auto assigned ASC-1, PC-02 manual assigned ASC-10(than click create button and automaticaly have assigned ASC-2) and PC-03 have auto assigned ASC-3.
    And if i change PC-02 ASC number to 500 the next PC created get ASC-4

    Its there something like read the last value and increment from that one?
    Please if anyone have any idea.
    P.S. i whant to migrate to ITOP and i wanna to keep ASC key but there are some gaps.
    the code is here:

    <methods>
                    <method id="DBInsertNoReload" _delta="define">
                        <static>false</static>
                        <access>public</access>
                        <type>Overload-DBObject</type>
                        <code><![CDATA[
                            public function DBInsertNoReload()
                            {
                                $oMutex = new iTopMutex('physicaldevice_insert');
                                $oMutex->Lock();
                                $iNextId = MetaModel::GetNextKey(get_class($this));
                                ///$sRef = $this->MakePhysicalDeviceRef($iNextId);
                                $this->Set('ASC', $sRef);
                                $iKey = parent::DBInsertNoReload();
                                $oMutex->Unlock();
                                return $iKey;
                            }
                        ]]></code>
                    </method>
                    <method id="MakePhysicalDeviceRef"  _delta="define">
                        <static>false</static>
                        <access>protected</access>
                        <type>Overload-DBObject</type>
                        <code><![CDATA[
                            protected function MakePhysicalDeviceRef($iNextId)
                            {
                                var_dump(get_class($this));
                                {
    
                                    $sFormat = 'ASC-%s';
    
                                }
                                return sprintf($sFormat, $iNextId);
                            }
                            ]]></code>
                    </method>
                </methods>
    
     

    Last edit: Popa Silviu 2021-03-08
  • Pierre Goiffon

    Pierre Goiffon - 2021-03-08

    Hello,

    Not sure to understand : do you want to import existing data having gaps in their ref fields, or do you want to be able to introduce gaps in the future tickets created in iTop ?

     
  • Popa Silviu

    Popa Silviu - 2021-03-08

    i want to import the existing data that have gaps ref fields.
    and to continue to increment the ASC numbere from last one added

     
  • Pierre Goiffon

    Pierre Goiffon - 2021-03-08

    Ok, that shouldn't be a problem.
    What iTop version are you using ? The Ticket.ref value generation was changed in 2.7.0

     
  • Popa Silviu

    Popa Silviu - 2021-03-08

    I use iTOP version 2.7.3,
    I realy dont know how to do it, but i will realy need that

     
  • Pierre Goiffon

    Pierre Goiffon - 2021-03-09

    Are you migrating from an existing iTop instance ? Or another app, which would need an import procedure ?

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.