Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X
I have a datatable with productname as primary key. i have two list widgets, one for product name and one for quantity. Now, for examples, if i select a product,say, a PCB and quantity as 2, then my datatable should make 2 entries having product name as PCB only. how do i do that?
Solved! Go to Solution.
You should call Add service in the new service you are creating.
You can check also AddorUpdateDataTablesEntries (this is allowing you to add more than one entry in datatable).
Regards,
Raluca Edu
Hello @gourinaik98,
If you use product name as primary key, you won't be able to insert two rows into your data table with the same product name. You should either insert one row with quantity = 2, or insert two rows, but use a combination of product name + quantity as your primary key.
/ Constantine
It's a composite primary key rather than two different keys. Just check "Primary key" for two fields in your datashape.
Yes I did that, but still I'm getting a single entry. I'm using the inbuilt AddDataTableEntry Service
If you have a composite PK, and you're inserting two rows with different values for at least on of the sub-fields, then it should work. If it doesn't, then I guess you should share some code to better understand the issue.
as you can see in the attached photo, i have selected quantity as 2. I must get two rows in the table. I haven't written any code as such, just used the already present services of the datatable to add the data to the DT ie, AddDataTableEntries.
The second image shows the service to get quantity.
Sorry, those two screenshots don't have anything in common, can't see how they are connected. There must be something between the service on your 2nd screenshot and AddDataTableEntry, which actually fills the infotable that you are trying to insert.
yes there is. The selectedrows of quantity service is bound to the values.quantity of AddDataTableEntry service
Hi,
I would do this in the following way:
- I would add an id column to the data table and I will make it as primary key;
- I would keep a counter of the id somewhere (persistent data/property), this would simulate a sequence;
- when I need to use AddDataTableEntry , I would create wrapper service to do that and insert as many rows as I need based on the input, but every time I will increment my counter for id;
Don't know if this helps you or it is in accordance with your business requirements, but thought to give you another idea.
Best regards,
Raluca Edu
Hi,
Yes this could help, but I am new to Thingworx. It would be great if you could elaborate with an example or share some article/tutorial regarding this.
what do you mean by a wrapper service?
Hi,
It is a service that encapsulate the logic of another service, in this case AddDataTableEntry.
For example, you create your service "updateMyDataTable", where you have as inputs the 2 values from your form, and after this you call AddDataTableEntry for every set of data you have. After every call of AddDataTableEntry, you increment the counter for id (primary key).
"UpdateMyDataTable" could trigger when a button is clicked.
Hope it helps,
Raluca Edu
You should call Add service in the new service you are creating.
You can check also AddorUpdateDataTablesEntries (this is allowing you to add more than one entry in datatable).
Regards,
Raluca Edu