New field with auto-increment

ericeger
Tera Guru

Hi everyone,

I created a field "Reference event" that I want to act similar to how Incident works with auto-increment with the prefix INC.   I made a new prefix in Number Maintenance and added a business rule with a condition "current.event_reference.nil() and a script:

function onBefore(current, previous) {

    current.event_reference = getNextObjNumberPadded();

            gs.addInfoMessage("Created Incident " + current.event_reference );

   

}

The column in my table has the default value Next Obj Number Padded.   When I go to my form, it is not showing a value at all.   Anything else I should consider? Any help would be great, thanks!

5 REPLIES 5

venkat2
Kilo Expert

Please check the dictionary entry for the number field and replicate the dynamic default value.



Number Padding.jpg


Hi Venkat,



I checked the dynamic default value and it had Get Next Number, but I changed it to be Get Next Padded Number.   Now when I view my form, I get an error up top that says getNextObjNumberPadded undefined, maybe missing global qualifier.



What else should I be looking for?


venkat2
Kilo Expert

Hi


The Number maintenance is set based on the table and if selected table is Incident then the increment is done for the INC counter for both fields.



I did try it on the demo013 instance on the incident form. See a field "Test" which is set to increment.



If you want to maintain its own counter then there are 2 options.



1. Create a new table to hold the number counters for the TEST field value.


2. If you dont want to create a new table, then everytime the incident is created a business rule should run to check all the incident records for the latest counter of TEST field and increment the counter using the regular count++ expression in business rule.



Please let me know if this helps.


Hey Venkat,



In the long run, I decided it would be actually be easier to extend the Incident table and re-label "Number" to "Reference Event" for my instance.   Thank you for the tips though, I will keep them in mind if I do it again!



Eric