Skip to main content
1-Visitor
August 14, 2014
Question

Check if user is enabled

  • August 14, 2014
  • 2 replies
  • 1152 views

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

    2 replies

    5-Regular Member
    August 14, 2014

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



    1-Visitor
    August 15, 2014

    Thank you Adam! That was a huge help!