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

Community Tip - Help us improve the PTC Community by taking this short Community Survey! X

Unordered DataTable entries when adding new rows

ashleyg
1-Newbie

Unordered DataTable entries when adding new rows

Hi All,

I am currently working on a geofencing project and have set up a DataTable to store temporary location vaues for users to freeform a geofence and create a region when they wish. I have a service which adds a DataTable entry every time a user double clicks the Google Maps widget where they would like to create a freeformed geofence. The primary key for this DataTable is currently setup to be an "ID" integer property of the DataTable which increments after every DataTable Entry.


The service below is what I use to add a location to the DataTable everytime the user double clicks the Google Maps widget:

var values = Things["GeofenceFreeformLocationsDataTable"].CreateValues();

values.location = location; //LOCATION

values.ID = me.ID;

var params = {

  sourceType: undefined /* STRING */,

  values: values /* INFOTABLE*/,

  location: location /* LOCATION */,

  source: undefined /* STRING */,

  tags: undefined /* TAGS */

};

// result: STRING

var id = Things["GeofenceFreeformLocationsDataTable"].AddDataTableEntry(params);

me.ID = me.ID + 1;

However for some reason when adding DataTable entries they seem to be added to the DataTabe in an unordered way (see below). This is bad as when creating a region because the locations are out of order and therefore produce an obscure polygon when executing the CreateRegion() service I have.

Unordered DataTable Entries.png

Note: My mashup is rather full of scripts making development in the mashup editor slow with multiple services running at the same time, could this be a possible cause? Could the system settings possibly cause my issue? Also notice my timestamp appears to be midnight of the current day, is this a possible cause?

Is it possible to add DataTable entries in order without having too manipulate the unordered DataTable in a service?

Any advice would be greatly appreciated.

Many Thanks

Ashley

1 ACCEPTED SOLUTION

Accepted Solutions

Hi

I think you'll have to modify your service that retrieves the region data for the map to sort by ID. Just use the InfoTable Sort snippet to do it.

Regards

Ian

View solution in original post

2 REPLIES 2

Hi

I think you'll have to modify your service that retrieves the region data for the map to sort by ID. Just use the InfoTable Sort snippet to do it.

Regards

Ian

Hi Ian,

Yeah it's a shame there's no automatic way of adding DataTable entries in a specified order e.g. by ID, timestamp, etc

Thanks

Ashley

Top Tags