Share via


SharePoint ReadOnly Field can be written to by workflows

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!

Comments