2 Replies Latest reply on Aug 15, 2014 12:08 AM by michaelfr RSS
    michaelfr Creator

    Check if user is enabled

    Hello,

    I want to return a list of users, however I do not want to include the ones that are not enabled. How can I differentiate them?

    Thank you,

    Mike

      • Check if user is enabled
        adam Creator

        Hi Michael,

         

        Unfortunately, there isn't an easy way to generate a list of only enabled

        Users

        . I've requested a couple

        Services

         from development that will

         

        make this much easier. For the time being, you'll need to get all of the

        Users

        , iterate through the resulting

        InfoTable

         and use a REST call to get the

        User

         as JSON. Of course, then you'll need to parse through the JSON to find the value for "enabled". If the value is true, you'll add it to another

        InfoTable

         that you will return (or alternately, if it's false, you could remove disabled

        Users

         from your initial

        InfoTable

        ).


        Here's the code:


        var users = Groups["Users"].GetGroupMembers(); // Get All Users


        var numberOfUsers = users.RowCount();


        var headers = new Object();

        headers.Accept = "application/json";


        var i = 0;


        while (i < numberOfUsers) {

          var user = Resources["ContentLoaderFunctions"].GetJSON({

            headers: headers,

            url: "http://localhost/Thingworx/Users/" + users[i].name,

            username: "Administrator",

            password: "admin",

            ignoreSSLErrors: true,

            withCookies: true,

            timeout: 30

          });

            

          if (user.enabled == "false") {

            users.RemoveRow(i); // Remove Disabled User      

            numberOfUsers--; // Decrement Number of Users

          } else {

            i++; // No Users Removed

          }

        }


        result = users; // Return Final InfoTable



        • Check if user is enabled
          michaelfr Creator

          Thank you Adam! That was a huge help!