cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Auto increment values.

SOLVED
Highlighted
Regular Member

Auto increment values.

Hi everyone. Is there anyway to create an auto increment field in a datatable? if so, can you provide me an example? Thank You for your time.

Tags (2)
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Auto increment values.

Hi Autoincrements should never be implemented with a getRowCount, in any platform.

We implemented on ThingWorx using a LONG property on the DataTable Thing, and you just increment it, and use it's value, of course make it persistent, this way you will lock other threads entering on the property while you are updating it and you won't lose last increment . In order to reuse it, we did it on a ThingShape that we add on the DataTable that we wan't an autoincrement.

View solution in original post

4 REPLIES 4

Re: Auto increment values.

Eddison, you can do this by calculating the rows in the data table something like this

// max number of rows fetched from the table in a pass

var params = {

  maxItems: undefined /* NUMBER */

};

// result: INFOTABLE

var result = Things["DataTableName"].GetDataTableEntries(params);

var finalResult= (result.getRowCount() +1);

But if you expect to have large number of entities you'd be better of using an RDBMS table to store that and not to mention that they have inbuilt feature to auto increment the values. Since using this method on a Data Table could affect the performance...

Re: Auto increment values.

I was thinking about that way, but It's not good, since values can be duplicated

Re: Auto increment values.

Hi Autoincrements should never be implemented with a getRowCount, in any platform.

We implemented on ThingWorx using a LONG property on the DataTable Thing, and you just increment it, and use it's value, of course make it persistent, this way you will lock other threads entering on the property while you are updating it and you won't lose last increment . In order to reuse it, we did it on a ThingShape that we add on the DataTable that we wan't an autoincrement.

View solution in original post

Re: Auto increment values.

Thank You, Carles. That's a great idea.

Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________