Skip to main content
11-Garnet
March 1, 2024
Solved

modify Data Table

  • March 1, 2024
  • 2 replies
  • 1679 views

hello,everyone!

I want to change the data in the table automatically through the service.Please tell me what to do.企业微信截图_17092786501957.png

Best answer by Velkumar

Hi @Snoopy_hu 

 

Please find below code to update dataTable value through service or subscription

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DATASHAPENAME)
let data = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "DATASHAPENAME"
});
 
let newObject = new Object();
newObject.bName = "test1"; // MAP YOUR INPUT FROM SERVICE OR SUBSCRIPTION
newObject.bDate = 25; // MAP YOUR INPUT FROM SERVICE OR SUBSCRIPTION
data.AddRow(newObject);
 
// id: STRING
let id = Things["DATATABLENAME"].AddOrUpdateDataTableEntry({
	sourceType: undefined /* STRING */,
	values: data /* INFOTABLE */,
	location: undefined /* LOCATION */,
	source: undefined /* STRING */,
	tags: undefined /* TAGS */
});

 

/VR

2 replies

19-Tanzanite
March 1, 2024

Hi @Snoopy_hu 

 

There are multiple services in DataTable to update data.

 

You can use any one of services ( based on your requirement ) below to update data in DataTable

  • AddOrUpdateDataTableEntries
  • AddOrUpdateDataTableEntry
  • UpdateDataTableEntries
  • UpdateDataTableEntry

/VR

Snoopy_hu11-GarnetAuthor
11-Garnet
March 4, 2024

Hi @Velkumar 

I tried it and it did work, but how can I get to the point of automatically changing the value through services and subscriptions?

Velkumar19-TanzaniteAnswer
19-Tanzanite
March 4, 2024

Hi @Snoopy_hu 

 

Please find below code to update dataTable value through service or subscription

// CreateInfoTableFromDataShape(infoTableName:STRING("InfoTable"), dataShapeName:STRING):INFOTABLE(DATASHAPENAME)
let data = Resources["InfoTableFunctions"].CreateInfoTableFromDataShape({
 infoTableName: "InfoTable",
 dataShapeName: "DATASHAPENAME"
});
 
let newObject = new Object();
newObject.bName = "test1"; // MAP YOUR INPUT FROM SERVICE OR SUBSCRIPTION
newObject.bDate = 25; // MAP YOUR INPUT FROM SERVICE OR SUBSCRIPTION
data.AddRow(newObject);
 
// id: STRING
let id = Things["DATATABLENAME"].AddOrUpdateDataTableEntry({
	sourceType: undefined /* STRING */,
	values: data /* INFOTABLE */,
	location: undefined /* LOCATION */,
	source: undefined /* STRING */,
	tags: undefined /* TAGS */
});

 

/VR

Rocko
19-Tanzanite
March 1, 2024

You can use the UpdateDataTableEntry service of the DataTable entity for this.

Rocko_0-1709284444308.png

 

Snoopy_hu11-GarnetAuthor
11-Garnet
March 4, 2024

Hi @Rocko 

I tried it and it did work, but how can I get to the point of automatically changing the value through services and subscriptions?