Skip to main content
Solved

Test SDK: How to Get Values based on a condition


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?

 

 

Best answer by rakshandad31

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

View original
Did this topic help you find an answer to your question?

3 replies

Forum|alt.badge.img+1
  • Varsity I
  • 28 replies
  • November 21, 2023

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


  • Jr Varsity I
  • 7 replies
  • Answer
  • November 22, 2023

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


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings