Create uniqueId on Child tables

Does anyone know how to programitically create a unique Id on a child table?

We currently have a field on our child table called unique id that we require the user to manually insert a unique id for each child table row. This is not an ideal solution.

It seems there should be an easy way to do this behind the scenes w/out having the user insert the id manually. It would simply need to increment a new value for each row i = i +1 and then store it in a hidden field. Has anyone implemented something like this?

-Jonathan

Hi Jonathan

Which database are you using?

in SQL Server you can set the identity of column passing in a seed and increment

CREATE TABLE test_table
(
 id_num int IDENTITY(1,1),
 name varchar (20)
)

You can also do this easily in Management Studio as well.

Cheers
James

Hi James,

We only want the unique id to count the actual number of child table items, not the total number of row in the child table. I think your method would add a new id for each revision as well.

-Jonathan

Hi Jonathan

If it just the number of children you want then you can use the size function once the list has been created:

#set($childresults = $rx.asmhelper.assembleChildren($sys.assemblyItem,$sys.item,$childname,$templatename))
#set($noofchildren = $childresults.size())

The above is just taken from the #children velocity macro.

Cheers
James