views:

1585

answers:

4

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.

+1  A: 

Does this help?

SPUser user = SPContext.Current.Web.CurrentUser;
Hans Malherbe
is there a way I can do it without going to VisualStudio?
YeomansLeo
+3  A: 

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
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?
YeomansLeo
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
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
You are right Kit, I did not build my custom list on C#.
YeomansLeo
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
+1  A: 

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
A: 

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.

Wartickler