SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Is it possible to change the data source on a lookup column? I have the source set to list A but I want to change it to List B.

share|improve this question
    
Does the list have data? If so, have you thought about what will happen to it if you are able to do this? – Derek Gusoff Sep 20 '12 at 23:25
up vote 1 down vote accepted

Disclamer: I can not say this is good practice, or very wise, or that it will not break anything.

You can update the SPField Schema XML directly, for example using Client Object Model like this:

var fromList = 'MyList';
var fromField = 'SomeLookupField';
var toListId = '{aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaa}';
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();
});
share|improve this answer

Or You can try this:

$w=get-spweb http://site/
$f=$w.fields["field_name"]
$f.schemaXml = "schema xml with another list ID"
$f.update()
share|improve this answer

You cannot achieve that from the UI, you must use SharePoint Powershell Management shell directly from the app server machine. This is the cleaner and most immediate approach:

$sitecol = Get-SPWeb http://yousite/coll
$lookup = $sitecol.Fields["YourLookupField"]
$schema = [xml] $lookup.SchemaXml

# in this example i'm going to reset the lookup list
$schema.Field.Attributes["List"].Value = "{" + $sitecol.Lists["YouNewLookupList"].ID + "}"
# you can also change the display value for the lookup
$schema.Field.Attributes["ShowField"].Value = "Title"

$lookup.SchemaXml = $schema.OuterXml
$lookup.Update($true)
$sitecol.Dispose()

# if you have set to show additional fields for the lookup, 
# you have to to the same for those fields. 
# You can list them as follows:

$sitecol.Fields | ? { $_.Title -match "YourLookupField" }
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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