Topic: Users & Roles - Accessing fields

I've implemented the users & roles introduced in V6.1 into my project but have a question about using the logged in username.

What I need to do is prefill a combobox on a form with the current logged in user. How do I achieve this?

Re: Users & Roles - Accessing fields

Hi,
I don't have an example with users and roles but the syntax should be the same.
Please have a look at the attached which allows for the username to be either entered in an edit field or selected from a combobox (comment out whichever option you don't use in the script). 
Then the value entered in the sign-on screen carries forward to a new form and pre-fills the combobox with the logged in user.
Derek.

Post's attachments

Attachment icon dynapta.zip 335.84 kb, 278 downloads since 2020-02-17 

Re: Users & Roles - Accessing fields

Hi Derek,

Thanks for the example. I had a very similar piece of code in my project before I implemented the new features from v6.1.

What I really need to know is how the reference the field on the new login form. I see how to use the code but as no one can see this form I don't know the field name for the combo box.

I hope this makes sense? May need the authors help on this one.

Re: Users & Roles - Accessing fields

Hi,
If you can attach your project, I can have a mooch around - I guess it has to be in there somewhere!
Derek

5 (edited by Dynapta 2020-02-18 14:43:55)

Re: Users & Roles - Accessing fields

I couldn't really upload the actual project as it has private customer data in it. What I've done is create a mini example of what I'm trying to do (attached zipped file).

Login with admin & admin and the "Amended by" field on form1 needs to be prefilled with the logged in user.

Post's attachments

Attachment icon dynapta.zip 326.12 kb, 256 downloads since 2020-02-18 

6 (edited by derek 2020-02-18 17:03:12)

Re: Users & Roles - Accessing fields

Hi Dynapta,
Never having used the roles/users function before, I didn't appreciate what the problem was - nothing to refer to!!
Anyway, I'm wondering if you can get around it by doing it this way (please see attached).  Of course. you could always use a variable instead of adding another text box to the form but I usually do it that way because I like to see what's going on (and then hide the text box afterwards).
I was unable to add any more users to test it thoroughly, so could only show that it worked by using 'admin' but I can't see why it wouldn't be okay.
The only other problem might be if you have multiple users who signed in simultaneously (to the split second!!) which is unlikely.
Anyway, hope this gives you some ideas.
Derek.

Post's attachments

Attachment icon dynapta2.zip 337.3 kb, 287 downloads since 2020-02-18 

Re: Users & Roles - Accessing fields

Derek,
Yes exactly the main problem was that I had nothing to refer to!
Your example will work for me though I probably use a variable to hold the logged in user.
I tested with the two users you added and all looked ok.
Multiple logins will happen but unlikely they will sign in at the same time to the split second!

I do remember reading that Dmitry saying that in a future version we would be able to design the login form ourselves to make something less generic and more custom. Hopefully this will help in my quest to find out how to refer to the username field on the login form. Perhaps he'll read this and comment?

Dynapta.

Re: Users & Roles - Accessing fields

In the current version you can use object User.

    User.id;
    User.Username;
    User.Email;
    User.First_name;
    User.Last_name;
    User.Role;
    User.RoleId;
    User.is_admin;
    User.is_active;
    User.is_logged;
    User.Last_login;
    User.Date_joined;
Dmitry.

Re: Users & Roles - Accessing fields

Thanks Dmitriy,

When you say current version you mean 6.2?

The only other thing is Iā€™m new to using objects in MVD scripts. How would I go about say storing the logged in user straight after logging in so that I reference throughout the script for the database? Any examples appreciated.

Regards,

Re: Users & Roles - Accessing fields

Yes, 6.2


Please provide some example, what exactly do you need?

Dmitry.

11 (edited by Dynapta 2020-03-13 14:52:25)

Re: Users & Roles - Accessing fields

I've attached my original example.

In simple terms what I want is to take the logged in user and fill in the amended by field on the customers form.

The example has one user setup - admin with password admin.

Post's attachments

Attachment icon dynapta.zip 326.21 kb, 215 downloads since 2020-03-13 

Re: Users & Roles - Accessing fields

Check it out

Post's attachments

Attachment icon dynapta_fixed.zip 6.23 kb, 278 downloads since 2020-03-13 

Dmitry.

Re: Users & Roles - Accessing fields

Thanks Dmitry

Exactly what I needed. I've upgraded to 6.3 as well and changed the code to "Application.User.id" all working now as I want.

My project is now nearly complete apart from one thing.....
Is there a way to disable header sorting on a tablegrid? So if a user clicks on a column nothing is resorted.

Re: Users & Roles - Accessing fields

Hi Dynapta,
Have a look at the attachment (I've disabled sorting on Column 0 as an example).
Derek.

Post's attachments

Attachment icon dynapta.zip 338.21 kb, 295 downloads since 2020-03-16