8 Replies Latest reply on Oct 16, 2017 10:22 AM by vxavier RSS
    vxavier Explorer

    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[x].Etapa /* STRING */,
            description: undefined /* STRING */,
            thingTemplateName: NomeDaObra /* THINGTEMPLATENAME */,
            tags: undefined /* TAGS */
        };
        Resources["EntityServices"].CreateThing(params4);
       
        Things[myInfoTable[x].Etapa].Enable(); 
        Things[myInfoTable[x].Etapa].Restart();    
        //inicio
        Things[myInfoTable[x].Etapa].Inicio = myInfoTable[x].Inicio;
        //fim previsto  
        Things[myInfoTable[x].Etapa].FimPrevisto = myInfoTable[x].FimPrevisto;
        //Porcentagem de Atraso
        Things[myInfoTable[x].Etapa].PorcentagemDeAtraso = myInfoTable[x].DifferencePercentual;
        //Porcentagem Concluída
        Things[myInfoTable[x].Etapa].PorcentagemConcluida = myInfoTable[x].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.

      • Re: Create Things Name error
        supandey Collaborator

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

         

        Also, I would test by putting that into a variable first something var strValue = myInfoTable[x].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.

          • Re: Create Things Name error
            vxavier Explorer

            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.

              • Re: Create Things Name error
                supandey Collaborator

                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.

                  • Re: Create Things Name error
                    vxavier Explorer

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

                      • Re: Create Things Name error
                        supandey Collaborator

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

                          • Re: Create Things Name error
                            vxavier Explorer

                            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?

                              • Re: Create Things Name error
                                wposner-2 Creator

                                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. 

                                  • Re: Create Things Name error
                                    vxavier Explorer

                                    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.