Page 1 of 1

How to obtain username, name and email of current user?

Posted: Wed Jul 18, 2018 4:13 pm
by ezavalah
Hello

I am a Beginner here so I ask for your patience.

I need to obtain and save into variables the name of user, username an email in order to show them in my dynaform.
I think this should be made in "Edit" part of the dynaform but I do not have clear how the code should be write to do it.
I am using ProcessMaker 3
Please would you give me some examples?

really thanks

Re: How to obtain username, name and email of current user?

Posted: Thu Jul 19, 2018 12:24 am
by amosbatto
Create three text fields in your Dynaform which are associated with the variables "username", "name" and "email".

Then, create the following trigger:
Code: Select all
$aUser = userInfo(@@USER_LOGGED);
@@username = $aUser['username'];
@@name = $aUser['firstname'] .' '. $aUser['lastname'];
@@email = $aUser['mail'];
Set this trigger to execute before the Dynaform in the "Steps" of the task.
See: http://wiki.processmaker.com/3.1/Proces ... Info.28.29

Re: How to obtain username, name and email of current user?

Posted: Fri Jul 20, 2018 11:31 am
by ezavalah
Really Thanks Amosbatto.

It works perfectly and motivate me to continue discovering ProcessMaker.

I hope having your support forward.

have a Nice Day.

Ernesto

Re: How to obtain username, name and email of current user?

Posted: Tue Jun 04, 2019 2:04 pm
by incitegraphics
Is there anything special we need to do to get this to work with a Web Entry form? Our users have the ability to login via SSO via SAML and we would like to have their names prepopulate in the forms. I've tried the code above in a trigger before the dynaform and tested it out, but it doesn't seem to work.

Re: How to obtain username, name and email of current user?

Posted: Tue Jun 04, 2019 2:31 pm
by amosbatto
incitegraphics wrote:Is there anything special we need to do to get this to work with a Web Entry form? Our users have the ability to login via SSO via SAML and we would like to have their names prepopulate in the forms. I've tried the code above in a trigger before the dynaform and tested it out, but it doesn't seem to work.
Have you tried using the Single Sign On feature in the Enterprise Edition? If you combine that with the "Require user login" option in the Web Entry properties, then you should be able to obtain the username of the logged-in user.

If you marked the option "Authentication" > "Require User Login" in the Web Entry properties, then you can get the username of the logged-in user with this JavaScript code in the Web Entry's Dynaform and place the username in a textbox whose ID is "loggedUser":
Code: Select all
var loggedUsername = $("#userInformation", top.document).text().match(/\((\w*)\)/)[1];
$("#loggedUser").setValue( loggedUsername );

Re: How to obtain username, name and email of current user?

Posted: Tue Jun 04, 2019 3:20 pm
by incitegraphics
Thanks for the prompt response. I will try it and will let you know if it works.

Re: How to obtain username, name and email of current user?

Posted: Sun Jun 23, 2019 9:43 pm
by incitegraphics
We are using the SAML plugin (see screenshot). Does that make a difference? We tried to turn on the authentication for the form and added the code you provided and it is not working.
Screen Shot 2019-06-23 at 8.39.19 PM.png
Screen Shot 2019-06-23 at 8.39.19 PM.png (19.5 KiB) Viewed 1952 times

Re: How to obtain username, name and email of current user?

Posted: Thu Jun 27, 2019 2:33 am
by amosbatto
When the web entry form appears, is the name of the logged-in user listed in the header like this?
WebEntryWithName.png
WebEntryWithName.png (15.7 KiB) Viewed 1633 times