I’m in quite a bind here. I just need to update a taxonomy field in a list item, but I keep getting an “Updates are currently disallowed on GET requests. To allow updates on a GET, set the 'AllowUnsafeUpdates' property on SPWeb” exception.
The code is being executed from within a SharePoint workflow that automatically runs when a new item is added to the list. The workflow was developed from scratch in Visual Studio.
I have tried setting AllowUnsafeUpdates = true on the item’s Web property, the item’s Web.Site, and the item’s Web.Site.RootWeb (which should be the same as the item’s web because the list is in the root web). Also tried calling the Update() method on the web object(s) after setting allow unsafe updates, as one blog suggested.
I have also tried running the code inside SPSecurity.RunWithElevatedPrivileges(), and tried setting SPGlobalAdmin.AllowUnsafeUpdates = true.
The stack trace I get every time is this:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.ValidateFormDigest(String bstrUrl, String bstrListName)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.AddTaxonomyGuidToWss(SPSite site, Term term, Boolean isKeywordField)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.ValidateTaxonomyFieldValue(TaxonomyFieldValue taxFieldValue)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.ValidTaxonomyFieldValue(TaxonomyFieldValue taxFieldValue)
[According to .NET reflector the above methods should NOT be called, but here they are in the stack trace??
TaxonomyField.GetValidatedString() does not call TaxonomyField.ValidTaxonomyFieldValue() ]
at Microsoft.SharePoint.Taxonomy.TaxonomyField.GetValidatedString(Object value)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, TaxonomyFieldValue taxValue)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term, Int32 lcid)
at Microsoft.SharePoint.Taxonomy.TaxonomyField.SetFieldValue(SPListItem item, Term term)
[Customer specific code redacted]
at System.Workflow.ComponentModel.Activity.RaiseEvent(DependencyProperty dependencyEvent, Object sender, EventArgs e)
at System.Workflow.Activities.CodeActivity.Execute(ActivityExecutionContext executionContext)
1.Execute(T activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutor1.Execute(Activity activity, ActivityExecutionContext executionContext)
at System.Workflow.ComponentModel.ActivityExecutorOperation.Run(IWorkflowCoreRuntime workflowCoreRuntime)
One thing I do not understand is how the last 6 methods in the stack trace are getting called. When I look at TaxonomyField.GetValidatedString(Object value) in .NET reflector all it does is return value.ToString(). The value parameter passed in has the type TaxonomyFieldValue. I looked at TaxonomyFieldValue.ToString(), which is overridden, but all it does is use a string builder to concatenate some string values. Nothing that I can see calls the TaxonomyField.ValidTaxonomyFieldValue() method, so how is it showing up in the stack trace?
I’ve seen a couple of blog posts say that to get around this error you need to move your code so that it executes in a postback so that there are user credentials available or something. They all say they took the code that was throwing the exception and placed it inside a button click handler so it executed on postback. I don’t see any way to even try this out since we are using a workflow that starts automatically?
Any help is appreciated, Thanks!