billsecond
billsecond

Reputation: 612

Unable to update a list item from a workflow task in C#

I am not getting any exceptions, but the code below is simply not working. Any ideas?

SPSecurity.RunWithElevatedPrivileges(delegate() {            
        using (SPWeb web = this.workflowProperties.Web) {
        try {
          SPListItem item = web.Lists["NewHireFormsLibrary"].Items[workflowProperties.ItemId - 1];
          item["Field 1"] = "Gotcha!!!";
          item.Update();

          LogHistory("Information", "Workflow indexing complete.  " + item["Field 1"], "");
         }
         catch (Exception ex) {
             LogHistory("Error", ex.Message, ex.StackTrace);
         }
   }
)};

Upvotes: 0

Views: 1407

Answers (1)

Steve Danner
Steve Danner

Reputation: 22158

It looks like you are not referencing the field by it's Internal Name, which is how you have to reference fields when accessing them with the SPListItem's indexer. Try something like

item["Field_x0020_1"] = "Gotcha!!!";

and it should work. Note that Internal names never contain spaces and are replaced by their hex character string like above.

Upvotes: 2

Related Questions