I know there is a builtin field which does this work, but i need to create a custom one. So i tried to set the value with this code:
this.taskProperties.ExtendedProperties["RequestedBy"] = this.WorkflowProperties.OriginatorUser;The result was an exception. I tried to create an SPUserFieldValue in order to set the extended property using this object. Since i receive another exception i looked into the ULS logger and i found this:
System.InvalidOperationException: The platform does not know how to deserialize an object of type Microsoft.SharePoint.SPFieldUserValue. The platform can deserialize primitive types such as strings, integers, and GUIDs; other SPPersistedObjects or SPAutoserializingObjects; or collections of any of the above. Consider redesigning your objects to store values in one of these supported formats, or contact your software vendor for support.
The code below solved the problem
this.taskProperties.ExtendedProperties["RequestedBy"] = this.WorkflowProperties.Originator;Morality is: don't try stupid things and also refer to primitive types.
I don't see the difference
ReplyDeleteHi Martin, you're right, i wrote a wrong snippet.
DeleteI edited the post right now, Originator is a string type and must be used instead of OriginatorUser (SPUser type) in order to avoid the above error.
Thanks :)
Thanks Valerio.
ReplyDeleteAlong similar lines: If anyone is doing this with a user field other than the out-of-box ones, the following is a way to get the loginName string written into ExtendedProperties.
var userVal = new SPFieldUserValue(workflowProperties.Web, this.workflowProperties.Item["myFieldInternalName"] as string);
myTask_TaskProperties.ExtendedProperties.Add(myFieldGUID, userVal.User.LoginName);
Thanks Martin
Delete