Skip to main content
Solved

Test SDK: How to Get Values based on a condition

  • 21 November 2023
  • 3 replies
  • 69 views

I need to get all role names that are selected for the particular user. So that I could check if they’re correct.

Here is the code I wrote but it didn’t work:

users.UserRoles.Columns.Rolename.GetValues().Where(users.UserRoles.Columns.Selected, users.UserRoles.Columns.Selected.Equals(true), x => x.(it doesn’t find anything here));

 

Could someone please help me out?

 

 

3 replies

Userlevel 4
Badge +1

Hi @annanykolenko71,

The way I’ve been doing that sort of thing is with the below code

        public List<string> GetRoleNames()
{
SMAccessUsers users = new SMAccessUsers();
users.OpenScreen();
users.Form.Username.Select("admin");
List<string> roleNamesToReturn = new List<string>();

int pageCount = users.UserRoles.PageCount();
for (int y = 0; y < pageCount; y++)
{
int count = users.UserRoles.RowsCount();
for (int i = 1; i < count + 1; i++)
{
users.UserRoles.SelectRow(i);
if (users.UserRoles.Row.Selected.GetValue())
roleNamesToReturn.Add(users.UserRoles.Row.Rolename.GetValue());
}
}

return roleNamesToReturn;
}

 

Whenever I try to use the Rows property(as in users.UserRoles.Rows) it always returns an empty list, so that is why I have to iterate through everything element by element. 

Let me know if you run into any more issues!
Philip Engesser

Userlevel 3

Hi @annanykolenko71 ,

Please refer below code to get RolesList-

                List<string> lstroleNames = new List<string>();
                for (int i=0;i<= users.RolesList.RowsCount(); i++)
                {
                    if(users.RolesList.Row.Selected.GetValue().VerifyEquals(true))
                    {
                        lstroleNames.Add(users.RolesList.Row.Rolename.GetValue());
                    }                     
                }

 

hope this helps!!

Thank you so much! It worked.

Reply