Skip to main content
5-Regular Member
October 13, 2017
Question

Create Things Name error

  • October 13, 2017
  • 1 reply
  • 3504 views

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.

1 reply

5-Regular Member
October 16, 2017

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.

vxavier5-Regular MemberAuthor
5-Regular Member
October 16, 2017

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.

5-Regular Member
October 16, 2017

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.