nego
nego

Reputation: 13

UpdateListItem method and System Account

I've developed a Help Desk application in Visual Studio that uses a Sharepoint List to store the data.

My problem is that when i use the UpdateListItems method for submitting a new record, Sharepoint automatically assigns to the "Created By" (Author) field as "System Account" and this prevents the trigger of a workfow i created with Sharepoint Designer. I've tried to force the Created By field during submit by adding to my batch person id;#person username

but it will still show "System Account"!!

Any ideas!?

sorry for my bad english:(

Upvotes: 1

Views: 2101

Answers (2)

zincorp
zincorp

Reputation: 3282

Have you considered using impersonation to update the list item?

You need a user on the site who has the correct access that you can impersonate. Look into the SPSite constructor that gets passed in an SPUserToken.

SPUserToken token = targetWeb.AllUsers["BobTheImpersonationAccount"].UserToken;
using(SPSite impersonatedSite = new SPSite("http://siteurl", token))
{
    //Anything accessed through impersonatedSite and its child objects are now executing under the guise of BobTheImpersonationAccount

}

Upvotes: 1

Kit Menke
Kit Menke

Reputation: 7056

Option 1: "Update the workflow"

I would not recommend trying to change the Created By field. Instead, create a new People field (named Submitter or something) in your list and populate that with the user. The workflow should use the Submitter field instead of Created By.

Option 2: "Update your code"

If your workflow, can't be updated, then you'll have to change your code. Instead of submitting using the Service Account, you will need to submit using the credentials of the current user. This means that they will need to have the correct permissions to the list. I am not sure if your code is in a web part or not, so I can't really be more specific.

Upvotes: 0

Related Questions