2

I need to update the author of list items. The list item is being created by a separate workflow. SharePoint (as expected) is using the workflow user as the creator. One of the fields in the list item is the contact for that list item.

I've been able to manually update the author field (see How to Update "Created By" column through workflow?), but cannot get the same behavior through workflow. The field has already been marked as not read only, and the author can be changed using a custom edit form. If updating it manually were a viable option, this would be a perfect solution, but it isn't.

I have created a workflow, and have configured it to update the "Created By" field with both the value of the contact column as well as a fixed value. In both events, the workflow completes as expected, without errors, but does not update the author.

I am thinking a custom workflow action may be the only option, but I don't know how to write one, so it isn't a very good option for me (I do have basic C# skills and VS2013, so I'm willing to try if someone can help give me detailed guidance, but I don't have enough knowledge to do it without some hand holding).

I've found several code snippets on how to programatically update the author column, but don't know how to tie it in so that it gets updated automatically once the list item is created.

Thanks for any thoughts.

2

CreatedBy is read only field in Sharepoint. So you might not be able to change this with worklfow. One thing you can try is:

You can change the ReadOnly property of this field to false by SharePoint Manager in your server, and use a workflow to change it.

You can download Sharepointmanager from:

http://spm.codeplex.com/downloads/get/92976

Try with server object model:

 using (SPSite site = new SPSite(SPContext.Current.Web.Url))
            {
                using (SPWeb web = site.OpenWeb())
                {
                    web.AllowUnsafeUpdates = true;
                    SPList list = web.Lists["Shared Documents"];
                    SPListItemCollection items = list.Items;
                    SPListItemCollection oListCollection = list.Items;
                    foreach (SPListItem oListItem in oListCollection)
                    {
                        SPUser user = web.EnsureUser("username");
                        SPFieldUserValue oUser = new SPFieldUserValue(web, user.ID, user.LoginName);

                        oListItem["Author"] = oUser;//created by column value = "14;#Sowmyan Soman"
                        oListItem["Editor"] = oUser;//modified by column value = "14;#Sowmyan Soman"               
                        oListItem.Update(); 
                    }
                    web.AllowUnsafeUpdates = false;
                }
            }
  • The link I included in my original message suggested that. I had already set the ReadOnlyField property to $false in PowerShell, and I can update the field using a custom edit form without a problem - I just haven't been able to do it programatically. – mswanson May 22 '14 at 14:03
  • Aren't you able to set with Workflow also? – Aanchal May 22 '14 at 14:05
  • No - that's the problem. The workflow in SPD lets me set a step that looks like it should be updating the column, and it runs without error, but it doesn't actually do anything. Using the same action, I can have it set another field to a defined value, and that works, so I obviously have the workflow configured correctly. It doesn't seem to like that I'm updating a field that isn't supposed to be updated and just decides to ignore it instead. – mswanson May 22 '14 at 14:09
  • I am able to update the createdBy field with above code. Please try at your end. – Aanchal May 22 '14 at 15:41
  • Sorry for the dumb question, but where would I put that? I found a similar snippet in my research, but I proved to be too dumb to actually implement it. :) – mswanson May 22 '14 at 19:43
1
private void completeTask2_MethodInvoking(object sender, EventArgs e)
        {
            Guid TaskStatusFieldId = workflowProperties.TaskList.Fields["TestResult"].Id;
            string taskStatus = onTaskChanged2_AfterProperties1.ExtendedProperties[TaskStatusFieldId].ToString();

            if (taskStatus.Equals("Rejected"))
            {
                completeTask2_TaskOutcome1 = "Rejected from HR";
            }
            else
            {
                completeTask2_TaskOutcome1 = "Approve from HR";
            }
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.