cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Check if user is enabled

Visitor

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

2 REPLIES 2

Check if user is enabled

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



Check if user is enabled

Thank you Adam! That was a huge help!



Announcements

Thingworx Navigate content has a new home! Click here to access the new Thingworx Navigate forum! ______________________________