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

Community Tip - You can Bookmark boards, posts or articles that you'd like to access again easily! X

Update DT using service

AP_9587236
17-Peridot

Update DT using service

I have a datatable having fielddefinitions of datatype infotable(5 rows & 5 columns). I want to update those infotables fielddefinitions using script. I am trying to pass values in a query of UpdateDataTableEntriesWithQuery. But its not working!!

1 ACCEPTED SOLUTION

Accepted Solutions

I used this logic inside for loop, the custom datas are successfully updating inside Datatable. Thanks for your help.

 

updateValues = Things[DataTableName].GetDataTableEntries();

updateValues[i].Details[0].Name = Name1;
updateValues[i].Details[1].Name = Name2;
updateValues[i].Details[2].Name = Name3;
updateValues[i].Details[3].Name = Name4;
updateValues[i].Details[4].Name = Name5;
updateValues[i].Details[5].Name = Name6;// INFOTABLE

var params1 = {
tags : undefined,
source : undefined,
values : updateValues,
location : undefined
};

// UpdateDataTableEntries(tags:TAGS, source:STRING("me.name"), values:INFOTABLE(DTName), location:LOCATION):STRING
Things[DataTableName].UpdateDataTableEntries(params1);

View solution in original post

16 REPLIES 16
PaiChung
22-Sapphire I
(To:AP_9587236)

What exactly are you trying to do?

UpdateDataTableEntriesWithQuery would update matching rows in your table. (runtime operation)

but you say you want to update infotable field definitions which is a design time operation.

Yes, the description is misleading.

 

Are you trying to update the DataShape of your Datatable, or update the value of this DT? 

The infotable you mentioned is for your whole DT value entry, or a specific column which is an infotable typed property?

AP_9587236
17-Peridot
(To:zyuan1)

Exactly, The datatable having specific columns which is an infotable typed property? I want to update that column (having infotable datatype) through script(by getting datas from user).

PaiChung
22-Sapphire I
(To:AP_9587236)

You should be able to create an insert or update with a payload that has infotables in it.

I would start with the AddDataTableEntry snippet from 'snippets'

As the entries are already added, I just want to update the column (datatype infotable) inside datatable through service. Do you have any example code for that ? And please provide me more information about payload which you mentioned before.

PaiChung
22-Sapphire I
(To:AP_9587236)

The snippet should provide what your Values object should look like, which is why I pointed you to that snippet.

In thingworx 8.4 ?

PaiChung
22-Sapphire I
(To:AP_9587236)

All versions of Thingworx have a snippets section on the left when you create a new service.

I used this logic inside for loop, the custom datas are successfully updating inside Datatable. Thanks for your help.

 

updateValues = Things[DataTableName].GetDataTableEntries();

updateValues[i].Details[0].Name = Name1;
updateValues[i].Details[1].Name = Name2;
updateValues[i].Details[2].Name = Name3;
updateValues[i].Details[3].Name = Name4;
updateValues[i].Details[4].Name = Name5;
updateValues[i].Details[5].Name = Name6;// INFOTABLE

var params1 = {
tags : undefined,
source : undefined,
values : updateValues,
location : undefined
};

// UpdateDataTableEntries(tags:TAGS, source:STRING("me.name"), values:INFOTABLE(DTName), location:LOCATION):STRING
Things[DataTableName].UpdateDataTableEntries(params1);

@zyuan1 @PaiChung 

If i selected a dropdown from list widget to edit/update datatable & grid, the list widget is not showing the other values only for second time of same option. but for 1st,3rd,4th,....so on it is showing correctly for same option.

I attached the screenrecording, guide me with some solutions.  

PaiChung
22-Sapphire I
(To:AP_9587236)

You may want to start a new thread next time vs. embed a question within an existing thread.

 

I'm not sure why the drop down is behaving like that.

It almost looks like there is a filter based on your selection that is refreshing that dropdown.

The service for the dropdown should be a 'straight' GetDataTableEntries that isn't filtered nor should you have any assignment to SelectedRow(s) for the Widget.

You are of course using SelectedRows (and SelectedRows changed) on that particular service.

If you aren't filtering or setting selection in any way for the drop down, I would submit it as a bug.

@PaiChung 

after updating the values in datatable, do you have any idea of refreshing the grid? can we bind the ServiceInvokeCompleted to the grid to refresh it? 

You may try, but not sure if the script update will be as fast, so an instant QueryDatatableEntries service may have risk returning old value
AP_9587236
17-Peridot
(To:zyuan1)

there is no such option like i said before!! how i can update the grid after updating the datatable. 

PaiChung
22-Sapphire I
(To:AP_9587236)

Run a GetDataTableEntriesWithData after your update using ServiceInvokeCompleted

Datatables are synchronous, so the update should have finished.

If you were entering into streams that is a different story, since Streams are asynch

I cant. Because I am passing the filtered rows to the grid using service. 

1. Already a service is bind to grid. if i created a another service to bind after ServiceInvokeCompleted to grid, then that output cant be passed to grid. Because only one binding is possible to the input of grid. 

2. If I triggered the previous service which passing datas to grid, then list widget is missing values in dropdown particularly on second count. (ref: uploaded the video in previous message)

Top Tags