Skip to main content
1-Visitor
March 31, 2016
Question

Adding rows to an infotable

  • March 31, 2016
  • 1 reply
  • 16857 views

Hey there,

In the Thingworx scripts, how can you add a row to an infotable that is already existing? Is see there is an AddRow option and I try to add that to my me.thisInfo object, but it requires a "row" object as an argument and I do not know how to set that opject up. I tried a few ways and it accepted it but with no addition to the Infotable.

Within the infotable the data shape just has the field definition of "Names" Just to keep it simple for now.

Thanks for any help!

1 reply

1-Visitor
March 31, 2016

For what you say, should be that easy:

me.thisInfo.AddRow({ Names: "whatever Name"});

But for the record, in order to Add Row to a Property Infotable, better you Clone Infotable, modify it and then set it again the property:

  1. var clonedData = Resources["InfotableFunctions"].Clone( { t1: me.thisInfo });
  2. clonedData.AddRow({ Names: "whatever Name" });
  3. me.thisInfo = clonedData;
1-Visitor
March 31, 2016

Apart of the previous explanation, you may read this post: Re: Update Single InfoTable Row with a Service and what Pai Chung says about writing on infotable properties, you can simplify my code with:

  1. var clonedData = me.thisInfo;
  2. clonedData.AddRow({ Names: "whatever Name" });
  3. me.thisInfo = clonedData;

But it's important that you copy and set again the infotable property, otherwise it won't be persisted.

jjuran1-VisitorAuthor
1-Visitor
April 1, 2016

Thanks for the help! One more add on,

If I wanted to add a row with also an Integer id value it would be like

AddRow({Names: "Name", id: 1});

or now is that wrong? It doesn't seem to want to work for me not sure why. Thanks!

Also now when I add a row it adds one, but it is blank. Or set to the default if I set a default. Not sure why. Even when using a simple datashape with just a name field.