Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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
Hi Michael,
Unfortunately, there isn't an easy way to generate a list of only enabled
Users
. I've requested a coupleServices
from development that willmake this much easier. For the time being, you'll need to get all of the
Users
, iterate through the resultingInfoTable
and use a REST call to get theUser
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 anotherInfoTable
that you will return (or alternately, if it's false, you could remove disabledUsers
from your initialInfoTable
).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
Thank you Adam! That was a huge help!