FIX: Coercion Failed: Unable to transform the input lookup data into the requested type.

Scenario:
When trying to set a lookup field value in a sharepoint designer workflow you get this error:
Coercion Failed: Unable to transform the input lookup data into the requested type.

Background:
In a sharepoint blog site I wanted to add the post category field to the comments list in a column called PostCategory (lookup on categories). I chose to use a workflow for this task. The workflow is triggered on item creation and update.

Here is the simple worklfow I have created:




The key is the "Return field as" field in the last dialogue box. I was getting the Coercion Failed error when setting the field type as integer. Setting it to lookup id (as integer) solved the problem.