4 Replies Latest reply on Aug 23, 2017 8:11 AM by drichter RSS
    drichter Explorer

    Get thing by name

    Hi,

     

    My idear:

    I have a mashup which is slit into two sections.

    Section #1 is a list with names of existing things (only strings). If I click on a name a mashup with this selected thing is show in section #2.

     

    My problem:

    Section #2 is a submashup. I give the selected name as input into the submashup. I wrote a service which should give me the thing by name. I try this with:


    result = Things[Name];


    and with

     

    var params = {

        identifier: Name

    };

     

    result = Resources["EntityServices"].GetThingNameForIdentifier(params);

     

    The first variant throw a "Invalid Reference to ThingWorx Entity" error message in the script log.

    The second variant does not throw an error but its return undefinded.

      • Re: Get thing by name
        jamesm Creator

        Try result = Things[Name].name

         

        Thanks!

        -James

         

        Edit: Actually, I might be misunderstanding -- what are you trying to return? You can't just return the Thing, that would be an Object. Are you trying to return the Thing properties?

          • Re: Get thing by name
            drichter Explorer

            I try to show what I mean with an image:

            Zwischenablage03.png

            On the right side is a list of things. If I click of one of them the lower section have to change. The lower section is a submashup which have an input type of THINGNAME (which mean a thing). With the getThingByName I want that its return the thing of the selected thing name and put it in the input params of the second section.

          • Re: Get thing by name
            jamesm Creator

            It looks like you want to dynamically pull the properties of the selected thing based on the selection?

             

            If so, add the Thing as you would normally add data, but check the Dynamic button:

             

            Then bind your Thing name to the EntityName parameter on the service:

             

             

            Finally, trigger to run the service on the entity change event from your rmashup parameter.

             

            Hope this helps!

              • Re: Get thing by name
                drichter Explorer

                So, now I'm a little step fourther. I used

                 

                var params = {

                    identifier: Name

                };

                 

                result = Resources["EntityServices"].GetThingNameForIdentifier(params);

                 

                and Add a Identifier to the thing. Next I add a refresh to of getProperties-Service if the inputthing changed. The only problem that I still have, I will get the thing by name not by an extra identifier.