Suman Chakrabarti - SharePoint and ASP.NET blog

SharePoint, .NET, Social Computing and random bits of goodness

SharePoint ReadOnly Field can be written to by workflows

SharePoint ReadOnly Field can be written to by workflows

  • Comments 1

So, I scoured the internet (all of it, I swear) to find some information on readonly fields in SharePoint. Apparently, SharePoint workflows can write to readonly columns. The only problem I'm having now is getting the column to show up in a columns list.

private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e) {
  SPList list = workflowProperties.List;

  if (!list.Fields.ContainsField(FIELD_NAME))
    list.Fields.Add(FIELD_NAME, SPFieldType.User, false);

  SPFieldUser field = (SPFieldUser)list.Fields[FIELD_NAME];
  field.Title = FIELD_NAME;
  field.AllowDisplay = true;
  field.ReadOnlyField = true;
  field.ShowInDisplayForm = true;
  field.ShowInEditForm = true;
  field.ShowInDisplayForm = true;
  field.ShowInEditForm = true;
  field.ShowInListSettings = true;
  field.ShowInNewForm = true;
  field.ShowInVersionHistory = true;
  field.ShowInViewForms = true;
  field.Update();
}

private void codeActivity1_ExecuteCode(object sender, EventArgs e) {
  workflowProperties.Item["restricted"] = "test: " + DateTime.Now.ToShortTimeString();
  workflowProperties.Item.Update();
}

Woo- hoo! It works!

Leave a Comment
  • Please add 6 and 5 and type the answer here:
  • Post