3

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.

hyeomans
  • 4,522
  • 5
  • 24
  • 29

4 Answers4

5

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);
Johan Leino
  • 3,473
  • 1
  • 26
  • 27
  • It is exactly what I'm trying to do, but, an sorry for my ignorance but I am new to SP, where do I put this code you gave me? – hyeomans Jun 25 '09 at 19:11
  • You said you had a custom list. Then the best way is to put this code in a "custom" field control that renders your userfield. There might be another way to do this but that is what I would have done. There are a lot of posts here on SO on custom field control.Here is one example: http://stackoverflow.com/questions/997448/how-to-manage-column-based-access-control-in-sharepoint-lists/997773#997773 – Johan Leino Jun 25 '09 at 19:42
  • When he says "Custom List" I don't think he means that he wrote any C# code. When you click create, the choice is called "Custom List". – Kit Menke Jun 25 '09 at 19:54
  • Ah, OK then I get it. Maybe you could go with a choice of an eventreceiver that sets this "field" on your list upon itemupdating/updated or something. – Johan Leino Jun 26 '09 at 08:03
2

Does this help?

SPUser user = SPContext.Current.Web.CurrentUser;
Hans Malherbe
  • 2,988
  • 24
  • 19
2

If you want the current logged in user, just use the Created By field in the list. This column is automatically populated with the user who created the item.

Kit Menke
  • 7,046
  • 1
  • 32
  • 54
0

Try SharePoint Designer WF that takes Created By and sticks it in that field.

Or, hide the column using jQuery and just have it populate by using the default value of the field as [ME]. [ME] fills in the textbox with the currently logged in user.

Edit: This whole thing could be dealt with by just grabbing the Created By in the workflow. You don't even need to capture the value in a textbox. SharePoint knows who created the item already. This will actually result in a less complicated form.

Kristopher
  • 819
  • 14
  • 31