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

Community Tip - Your Friends List is a way to easily have access to the community members that you interact with the most! X

Create Things Name error

vxavier
13-Aquamarine

Create Things Name error

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.

8 REPLIES 8
supandey
19-Tanzanite
(To:vxavier)

Hi Vinicius, have you checked if myInfoTable.Etapa is really returning result of type String, as expected? May be you could try to print that out with a logger.info(myInfoTable.Etapa) statement?

Also, I would test by putting that into a variable first something var strValue = myInfoTable.Etapa and then assign that to the name parameter just to check if that works


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.

vxavier
13-Aquamarine
(To:supandey)

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.

supandey
19-Tanzanite
(To:vxavier)

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.

vxavier
13-Aquamarine
(To:supandey)

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().

supandey
19-Tanzanite
(To:vxavier)

Cool! So if I understand it right, all's working now?

vxavier
13-Aquamarine
(To:supandey)

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?

wposner-2
12-Amethyst
(To:vxavier)

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. 

vxavier
13-Aquamarine
(To:wposner-2)

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.

Top Tags