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
Hello,
I am trying to create things reading a infotable, and in this infotable each row has a name that is the "Etapa" field and its properties in the others fields.
var tableLength = myInfoTable.rows.length;
for (var x = 0; x < tableLength; x++) {
var params4 = {
name: myInfoTable
.Etapa /* STRING */, description: undefined /* STRING */,
thingTemplateName: NomeDaObra /* THINGTEMPLATENAME */,
tags: undefined /* TAGS */
};
Resources["EntityServices"].CreateThing(params4);
Things[myInfoTable
.Etapa].Enable(); Things[myInfoTable
.Etapa].Restart(); //inicio
Things[myInfoTable
.Etapa].Inicio = myInfoTable .Inicio; //fim previsto
Things[myInfoTable
.Etapa].FimPrevisto = myInfoTable .FimPrevisto; //Porcentagem de Atraso
Things[myInfoTable
.Etapa].PorcentagemDeAtraso = myInfoTable .DifferencePercentual; //Porcentagem Concluída
Things[myInfoTable
.Etapa].PorcentagemConcluida = myInfoTable .Percentage; };
But when I execute the code, I got the following error: Execution error in service script [LocalizationDT CreateDataStructureFromCSV] : Wrapped java.lang.Exception: No name provided in CreateThing Cause: No name provided in CreateThing
The Etapa field is a STRING, but I can't figure out why it isn't recognizing it as the name of my new Thing.
Thank you,
Vinicius.
Hi Vinicius, have you checked if myInfoTable
Also, I would test by putting that into a variable first something var strValue = myInfoTable
Finally, I test with something like this, which essentially the same as the InfoTable loop you are running but instead of using the length i simply just use a static value
for (var i = 0; i<5; i++) {
var result = allData.getRow(i);
Edit:
Would also recommend you to surround that createThing with try/catch block to ensure that you are not creating any GhostEntities when the statement fails to properly create the thing.
Thank you Sushant,
I tested it, it is returning the corret String.
The looping is working well for what I see.
I put it on try/catch.
Now I can create the things, but am not able to enable it. I tried and it isn't working.
Have you seen any error as to enabling the thing or when you restart it? It should be somewhere in the Application or Script log if its failing to restart it. If you want to include that check you can do so with the isEnabled service in your code.
I found the error. I was writing .Enable() and .Restart(), from what I saw in a post here. But the right is .EnableThing(), and .RestartThing().
Cool! So if I understand it right, all's working now?
This section of the project, yes.
But I am trying to do a big structure. I did a Shape manually, and from this shape I am creating thing templates and this using CSV files. Each CSV file is a Thing Template and all the things that inherits from it.
And What I need to do now is that each Thing Template will have a different Location, I want now a service that catch all the locations from all the Thing Templates that inherits from the thing Shape now to populate a google maps widget.
I want to return as also some fields of sum of the properties of the things that inherits from these things templates.
How can I, from the thing Shape, take the properties and values for each thing template, and from the thing templates, take property and values of each thing?
You should think of a thing shape as something more of which defines a thing template. And as you're aware, a template can have multiple shapes applied to it. Any service or property implemented on a template and shape is immediately available from the thing via "me.xxxx" were xxx is the name of a service or the name of a property. A thing shape has no native services on it and template has no native access to property values. Everything must be accessed from an implementing thing.
Thank You. What I did was creat another Thing Template that inherits the same Thing Shape. After that I created a single thing with the properties and the averages that I want. It seems to work fine until now. From this new Thing Template I can call all they.