Friday, November 27, 2015

SharePoint Migration Lookup error

There was site in SharePoint 2010 and I was planning to move it to SharePoint 2013 version by performing a Content db migration .

The site had a list which consists of lookup columns ,these were lookup to other list.But the point here was that these columns were hidden while it was created through element.xml in the solution .The list was working fine in SharePoint 2010 ,But when I migrated the 2010 site to SharePoint 2013 the link of the lookup is lost and the data is been displayed as a text field Eg: "#2;lookupValue" etc .
This was creating few problems in my solution due to mismatch in the values of the list itms .I had to fix the lookup column .Below is the resolution to this migration error

I placed the below code in Content Editor WebPart and made the field readable,This changed the column back as lookup .Later you can change the column to readonly =true

<content id="Main" contentplaceholderid="PlaceHolderMain" runat="server"></content><script language="ecmascript" type="text/ecmascript">
        var fieldCollection;
        var field;
        var list;
        function UpdateField() {
            var clientContext = SP.ClientContext.get_current();
            if (clientContext != undefined && clientContext != null) {
                var webSite = clientContext.get_web();
                this.list = webSite.get_lists().getByTitle("ListA");
                this.fieldCollection = list.get_fields();
                this.field = fieldCollection.getByTitle("Column1");

                clientContext.executeQueryAsync(Function.createDelegate(this, this.OnLoadSuccess), Function.createDelegate(this, this.OnLoadFailed));
        function OnLoadSuccess(sender, args) {
            alert("Field deleted successfully.");
        function OnLoadFailed(sender, args) {
            alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
</script><input type="button" id="btnUpdateField" onclick="UpdateField()" value="Change ReadOnly"/> 

No comments:

Post a Comment