Is there any chance to create a new autoincremental attribute field in a Class?
In my case, I need a new autoincremental attribute in the PC Class that has a prefix followed by a number that change every time I create a new PC.
Thanks a lot.
Cristian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Would it be safe to assume that this is always new, and never needs to be modified manually or anything?
Theoretically you could auto-calculate a field and apply some logic there to do exactly this. I've done something similar myself for invoices in iTop :)
Yes, I need that when will create a new physical device (PC, Printer, etc) a new field that his value be an autoincremental number, for example INV-00001, next, INV-00002 and so on.
My iTop version is 3.01.
Thanks for replay.
Cristian
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Yes, I need that when will create a new physical device (PC, Printer, etc) a new field that his value be an autoincremental number, for example INV-00001, next, INV-00002 and so on.
Do you mean you need all PhysicalDevice instances to have a specific reference field, like the UserRequest do ?
You didn't answer to my question about what 'it don't work" means ?
In the code you posted : $iNextId = ItopCounter::IncClass(get_class($this));
The counter should be set to the same key whatever the class is. Here you'll get a different counter for every classes (PhysicalDevice, PC, ...)
So you should change to something like : $iNextId = ItopCounter::IncClass('PhysicalDevice');
This is a problem I see, but please explain precisely what is wrong with your implementation ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Good Morning Pierre
Thanks for your answer, I will try you suggest.
My problem is that when create a new physical device there isnt any value. But ass you said, maybe my error was specify in your comment. Thanks again. if i can do it i will tell you
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The SetIfNull method won't update the field if it doesn't contain a NULL value... Maybe make the field read only for the users, and just call Set() directly ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello
Is there any chance to create a new autoincremental attribute field in a Class?
In my case, I need a new autoincremental attribute in the PC Class that has a prefix followed by a number that change every time I create a new PC.
Thanks a lot.
Cristian
Would it be safe to assume that this is always new, and never needs to be modified manually or anything?
Theoretically you could auto-calculate a field and apply some logic there to do exactly this. I've done something similar myself for invoices in iTop :)
https://www.itophub.io/wiki/page?id=latest%3Acustomization%3Acascade-update
Hello,
Since iTop 2.7.0 what you are asking is really easy to do thanks to the new ItopCounter class !
Check https://www.itophub.io/wiki/page?id=2_7_0:release:2_7_whats_new#ticket_ref_generation
Hello
I tried this in the CLASS PC but dont work
What is wrong?
Hello,
Can you explain what was your initial functionnal need ?
Also, what error are you getting and when ?
What is your iTop version ?
Yes, I need that when will create a new physical device (PC, Printer, etc) a new field that his value be an autoincremental number, for example INV-00001, next, INV-00002 and so on.
My iTop version is 3.01.
Thanks for replay.
Cristian
Do you mean you need all PhysicalDevice instances to have a specific reference field, like the UserRequest do ?
You didn't answer to my question about what 'it don't work" means ?
In the code you posted :
$iNextId = ItopCounter::IncClass(get_class($this));
The counter should be set to the same key whatever the class is. Here you'll get a different counter for every classes (PhysicalDevice, PC, ...)
So you should change to something like :
$iNextId = ItopCounter::IncClass('PhysicalDevice');
This is a problem I see, but please explain precisely what is wrong with your implementation ?
Good Morning Pierre
Thanks for your answer, I will try you suggest.
My problem is that when create a new physical device there isnt any value. But ass you said, maybe my error was specify in your comment. Thanks again. if i can do it i will tell you
EDIT 21/09 to add code blocks
Hi Pierre
This is my code, which does not generate any error but does not show me any value in the field asset_number. Alway appear empty.
Where do you thinks is the error.
Last edit: Pierre Goiffon 2022-09-21
There seems to be a missing
on your DBInsertNoReload() method?
Yes!!!, problem solve!.
Now I can automatically assign a new inventory number to each physical device.
Thanks a lot Jeffrey!
The SetIfNull method won't update the field if it doesn't contain a NULL value... Maybe make the field read only for the users, and just call Set() directly ?
Wooops forgot my previous answer sorry
You already explain the functionnal need :D
Can you reply and both other questions though ?