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

Community Tip - Have a PTC product question you need answered fast? Chances are someone has asked it before. Learn about the community search. X

modify Data Table

Snoopy_hu
11-Garnet

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

ACCEPTED SOLUTION

Accepted Solutions
Velkumar
19-Tanzanite
(To:Snoopy_hu)

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
Velkumar
19-Tanzanite
(To:Snoopy_hu)

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?

Velkumar
19-Tanzanite
(To:Snoopy_hu)

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!

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

Rocko_0-1709284444308.png

 

Snoopy_hu
11-Garnet
(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?

Announcements


Top Tags