Monday, February 15, 2010

SharePoint Exception: Coercion Failed: Input cannot be null for this coercion

This is the exception, I am seeing very first time in SharePoint development. What I tried was, through SharePoint designer I tried to update the list item. The source and destination lists are having a field of type choice. I want to grab the choice field information from source list and update the destination list choice field.
The problem occurs only when the source choice field is empty.

More clearly, I have a list with checkbox list field. When a new list item is added, the workflow triggers and start updating the another list item with the current item information. And when I select nothing in the checkbox list field, then it throws the exception "SharePoint Exception: Coercion Failed: Input cannot be null for this coercion".

So, why the problem comes?
Because in update list item phrase in SharePoint designer I have selected the lookup for choice Return field as as Choices, Comma delimited. See the below screenshot.
Once changed that back to the As String then everything worked perfect. But, didn't get the reason behind. When nothing selected, then it shouldn't do any operation. It should check for null and do nothing. May be a built-in problem or something interesting with this.

Hope this helps to understand it well and solve your problem.

6 comments:

  1. Thank you for putting this out here! This saved me hours today. I'm not a SPD workflow wizard, and I don't have access to one.

    ReplyDelete
  2. This also happens when email, semi-colon delimited is selected, and the user leaves the field blank.

    ReplyDelete
    Replies
    1. if I am using in a CC variable with email, semi-colon delimited will it still send the email normally when changed back to As String?

      Delete
    2. I am trying to do the same thing. It is not sending the email when I set it as a String. Not sure if there is a solution other then having to enter in Email To and Email CC

      Delete
  3. Thank you! I don't think I would have figured this out if you didn't post this message here.

    ReplyDelete
  4. If you create a workflow STRING variable then create a condition that only updates the variable if the value of the field is NOT EMPTY then you can set the variable to the value of the field (comma delimited) and use that variable in an email (as string - not comma delimited). You should not get a coercion-failed error if it's empty because SP is only checking a string value, not a comma-delimited value.

    You can use this trick for any SP field type. It seems best to only use string and number values when crafting the email template.

    ReplyDelete