How can I set a User field to a default value of a user currently logged in through XML in Sharepoint 2010?
Solution 1
Here is the closest I've ever come:
<Field ID="{99ced9dc-5715-47a7-9ede-1733f027eeb4}"
Name="MyField"
DisplayName="My Field"
Type="User"
List="UserInfo"
UserSelectionMode="PeopleOnly"
Required="TRUE">
<DefaultFormula>=";#"&Me</DefaultFormula>
</Field>
It doesn't blow up, but it doesn't give the desired result either. The problem is that Me
will give the name of the user, but since the User Field is a special type of Lookup Field, the name is ignored. All that is needed is the ID, but I haven't been able to find anything that will give me that value.
Here are some possible workarounds:
- Custom Field: Current user as default value for a SharePoint Person or Group field
- Event Receiver: Add current user to person field default value with event receiver ItemAdding–SharePoint
- Javascript: Current user as default value for a SharePoint Person or Group field
Solution 2
I do not think so there is any constant for the current logged in user similar to [today]
constant for DateTime type. So you probably have to create your own field inherited from SPFieldUser and parse the default value constant introduced by you, e.g. [current]
. Then your field xml definition can look like
<Field Type="MyCurrentUser" Name="MyCurrentUser" ID="{...}">
<Default>[current]</Default>
</Field>
UkraineTrain
Updated on July 21, 2022Comments
-
UkraineTrain almost 2 years
I'm trying to create an field definition in XML for a field of a User type and need to set its default value to a user currently logged in. How do I do that?
Thanks a lot in advance.