1

I've read a numbered time that SPFieldLookup is cross-site by its nature. But now I'm a little bit confused, here is my SharePoint structure:

  • /SiteCollection
    • /Site1
      • Projects
    • /Site2
      • Customers

Does cross-site mean that I can do a lookup field for Customers and access it within my Projectsform?

And if it is possible, how should I do it? I've looked into those articles but it seem to be for a site and his subsites only:

http://developing-dummy.blogspot.fr/2012/02/sharepoint-and-cross-site-lookup-fields.html

http://tjendarta.wordpress.com/tag/spfieldlookup/

7

Yes, you're able to create a Lookup column from another site. You can use the script bellow in PowerShell. It'll create a Customer lookup column in your Project list. Before running the script you'll need to update the url and list names with yours.

#Get the webs and lists
$web1 = Get-SPWeb http://sitecollection/site1/
$web2 = Get-SPWeb http://sitecollection/site2/
$projectList = $web1.Lists.item("Projects")
$customerList = $web2.Lists.item("Customers")

#Add a lookup field
$projectList.fields.AddLookup("Customer", $customerList.id, "false")

#Get the created lookup field
$LookupField = $projectList.Fields["Customer"]

#Set the lookup web ID and lookup field
$LookupField.LookupWebId = $customerList.ParentWeb.ID
$LookupField.LookupField = $customerList.Fields["Title"].InternalName
$LookupField.Update();
  • Please do not only link to answers, add an abstract of the information on the link (off course with a link to the source) :) – Robert Lindgren Oct 16 '13 at 11:38
  • @Robert, After reading your comment I figured out that I was wrong with my answer. Now it's updated. Thanks ;) – Carolina Bauque Oct 16 '13 at 12:30
  • Is there a way to do this through the GUI? – bgmCoder Mar 10 '14 at 18:28
  • No, there is no solution via GUI! Thank you very much, carobauque! – lex May 14 '14 at 13:35
0

Via UI it is not possible to create a site-cross lookup column. Taking a look on the Microsoft Documentation there is the method AddLookup(String, Guid, Guid, Boolean) where it is possible to specify also a web.

Example:

Add-PSSnapin *SharePoint*

$urlWeb1 = "http://sitecollection/site1/"
$guidList1 = "ProjectsGuid"

$urlWeb2 = "http://sitecollection/site2/"
$guidList2 = "CustomersGuid"

$isFieldRequired = $false #Or $true, depending on your needs

$web1 = get-spweb $urlWeb1
$list1 = $web1.Lists[[Guid]$guidList1]

$web2 = get-spweb $urlWeb2
$list2 = $web2.Lists[[Guid]$guidList2]

$list1.fields.AddLookup("NameOfTheNewColumn", $list2.ID, $web2.ID, $isFieldRequired )

Please use Guids!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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