Tuesday, November 27, 2012

Wrong Sharepoint lookup value

Issue:


You might not get an error but you might end up with a wrong lookup value.

Effect:

During data migration when associating source item lookup value to the target item lookup value directly. Please ensure that the lookup Id is the same for the source lookup value and the target lookup value, as it assigns whatever value is associated with the lookup Id got from the target side. This is fine as long as both the side’s lookup value has the same Lookup Id if not you will end up with a wrong value.

Cause:

As each lookup value’s Id is auto generated from its lookup master list. There are chances of id mismatch between the source side and the target side when items are deleted and entered repeatedly without uniformity.

Caution:

So please check your source and destination master lookup lists value-id association if you are facing a similar issue.

Code logic solution for above scenario:

Get the lookup value from the source item and query the master lookup list associated with the current lookup field and get the item id and associate it to your SPLookFieldValue.

Remove blank lines from code in Visual Studio

1. Click Ctrl+H (quick replace)
2. Tick "Use Regular Expressions"
3. In Find specify "^$\n"
4. In Replace box delete everything.
5. Click "Replace All"