Creating Lookup Columns using CAML

本文介绍了如何利用CAML(Collaborative Application Markup Language)来创建查找列,避免了使用非确定性的ListID,并详细说明了如何引用目标列表以及如何在相同列表中设置自参照查找列。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

Creating Lookup Columns using CAML

Published 08 August 09 08:31 PM

As List IDs are generated at runtime and are non-deterministic, it is not possible to refer to the target list using List Id. So, as a work around, most of the solutions on the internet suggest to write Custom Code. But this can be avoided and the lookup columns can be created using CAML as shown below:

While creating the lookup columns using CAML, the target list needs to be referred using the Url of the List Name instead of the List Id.

Note: Please note that the entire URL of the List need to be specified i.e., Lists/Products instead of just the list name

Also, the target list needs to be present in the folder, when this column is getting created.

<Field Type="Lookup" DisplayName="Language" Required="TRUE" List="Lists/Products" ShowField="Title"

UnlimitedLengthInDocumentLibrary="FALSE" ID="{52c458b8-5f67-428c-a675-02a0538e7c84}"

SourceID="{8ea5965e-0026-48c7-b426-a8bca5b4f543}" StaticName="Language" Name="Language"

ColName="int1" RowOrdinal="0" Group="" Version="1" />

Self referential Lookup Column:

For scenarios where you wanted to maintain a hierarchy among the items in the same list, you might want to refer a column in the same list.

But you cannot use GUID of the list, as the list is not yet created by then. In such scenarios, the same list can be referred by using the keyword “Self” as the List Name.

<Field Type="Lookup" DisplayName="Parent" Required="FALSE" List="Self" ShowField="Title"

UnlimitedLengthInDocumentLibrary="FALSE" ID="{d2a9d2e6-9beb-414d-bba6-fc0b3fa7e494}"

SourceID="{a26e88fb-94b6-4429-8d16-da52faa0250c}" StaticName="Parent" Name="Parent" ColName="int1" RowOrdinal="0" />

 

Field Type="Lookup" DisplayName="My Parent Item1" Required="FALSE" List="Self" ShowField="Site1" UnlimitedLengthInDocumentLibrary="FALSE" ID="{1367d8d7-aad2-4884-979d-af3fce0ef75c}" SourceID="{0014ECE1-8403-45f1-8DBA-D8A7E636C9EE}" StaticName="MyParentItem" Name="MyParentItem" ColName="int1" RowOrdinal="0"

/>

 

<

 

 

Field Type="Lookup" DisplayName="Reference Language" Required="TRUE" List="Lists/con1" ShowField="ItemName" UnlimitedLengthInDocumentLibrary="FALSE" ID="{52c458b8-5f67-428c-a675-02a0538e7c84}" SourceID="{0A7EFDEC-8B55-4918-850B-035B889A151C}" StaticName="Language" Name="Language" ColName="int1" RowOrdinal="0" Group="" Version="1"

 

/>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值