Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fill textbox with current username logged in sharepoint

I made a custom list, it is actually a form fill out for an absence request workflow. Before publishing it I found a flaw. The first textbox is a Person or Group textbox, this helps out to retrieve the Active Directory username, but the flaw is that I can type whatever username I want, Example:

"User X is logged on, but if he types User Y and hits enter he can request an absence for User Y"

So what I want is, hide the textbox and fill it automatically with the current logged on user.

I've been looking for formulas for the calculated textboxes but I haven't found anything.

like image 712
hyeomans Avatar asked Oct 26 '25 07:10

hyeomans


2 Answers

I´m not exacly sure what you wan´t to do here but if you have a peoplepicker that you want to fill with the current user, here is how to do that. Then you would have to disable the control in order for the user not to be able to change the value in it.

PickerEntity entity = new PickerEntity 
{ 
   Key = SPContext.Current.Web.CurrentUser.LoginName 
};

PeopleEditor.Entities.Add(entity);
PeopleEditor.UpdateEntities(PeopleEditor.Entities);
like image 117
Johan Leino Avatar answered Oct 28 '25 02:10

Johan Leino


Does this help?

SPUser user = SPContext.Current.Web.CurrentUser;
like image 33
Hans Malherbe Avatar answered Oct 28 '25 01:10

Hans Malherbe



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!