Reputation: 1309
I'd to allow the user to option to change the "created by" value when created an item in a sharepoint list. It seems that it's the default to hide this value and auto-populate the current user. I'd like to give the user this option when creating or modifying an item and pre-populate with the current user, but also give the user the option to change this field..
Anyone have any suggestions or whom can point me in the right direction?
Thanks very much
Upvotes: 3
Views: 3750
Reputation: 1309
Thanks, guys but I should've mentioned I'm not using any code for this.
My solution was to rename the Created By field to Created By (unused), created a new Created By field and used some custom Javascript to populate the field on page load.
Upvotes: -1
Reputation: 2104
The internal name of 'Created By' column is Author.
Write an ItemEventReceiver and override the ItemUpdated method:
//USER_NAME is user account name that you want to set.
public override void ItemUpdated(SPItemEventProperties properties) {
SPSecurity.RunWithElevatedPrivileges(delegate
{
using (SPWeb web = properties.OpenWeb())
{
web.AllowUnsafeUpdates = true;
// Insert any other updates here
SPUser spUser = web.EnsureUser("USER_NAME");
string strUserId = spUser.ID + ";#" + spUser.Name;
spListItem["Author"] = strUserId;
spListItem.Update();
// if you do not want to change the Modified or Modified By fields,
// use spListItem.SystemUpdate() instead
}
});
}
EDIT: updated code; removed iterative update.
Upvotes: 8