2

I have a SharePoint list with a lookup field, is it possible to change the target list fro UI? I don't have access to Powershell

enter image description here

Any thoughts how I could change the field without delete?

2 Answers 2

4

Unfortunately, There is no way to change the Get Information list of Lookup field through UI.

The available options are

  • Delete and recreate it again, in case it's a new column.
  • In case it's not a new column, Try to create a new column with the required list then updated its value using a workflow then delete old one
  • You can update the SPField Schema XML directly, for example using JS Object Model as mentioned at Change the source on a lookup column? (I don't think it's a good practice)
1
  • 2
    I Agree. JSOM is not a good approach as it can break the list very easily if the new schema that is used in the schema has even an extra character. Aug 7, 2017 at 14:11
3

You can test out the below JSOM code in a Content Editor Webpart. I have tested and it successfully changes the lookup list. But you will have to do further testing to ensure that nothing else is broken. This code directly changes the list field schema from client side which is not really a good approach as even the slightest error can make the list useless. Suggested approach would still be PowerShell Or Field Recreation.

The parameters :

fromList - Current List where look up field is present

fromField - LookUp field name

toListId - The New LookUp List guid which you can get as mentioned here

<script language="javascript" type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js"></script>

<script language="javascript" type="text/javascript">

$(document).ready(function() {

    SP.SOD.executeOrDelayUntilScriptLoaded(updateWebSite, "sp.js");

});
var oWebsite ;

function updateWebSite() {
var fromList = 'Check List';
var fromField = 'LookUpColumn';
var toListId = '{82b5a10b-f263-4b69-a67b-105d73dce817}';
var ctx = new SP.ClientContext();
var field = ctx.get_web().get_lists().getByTitle(fromList).get_fields().getByInternalNameOrTitle(fromField);

ctx.load(field);
ctx.executeQueryAsync(function() {
var schema = field.get_schemaXml();
schema = schema.replace(/list=\"\S*\"/i, '').replace(/\/\>/, 'List="' + toListId + '" />');

field.set_schemaXml(schema);
ctx.executeQueryAsync();
});

}
</script>

The above code changed the look up list from Approval List to Accordion

Before running the script : enter image description here

After running the script :

enter image description here

Reference

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.