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

Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X

modify Data Table

Snoopy_hu
9-Granite

modify Data Table

hello,everyone!

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

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

6 REPLIES 6

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

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?

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

Hi @Velkumar 

I tried it with your code and it worked, thank you so much!

Rocko
17-Peridot
(To:Snoopy_hu)

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

Rocko_0-1709284444308.png

 

Snoopy_hu
9-Granite
(To:Rocko)

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?

Top Tags