1

I have a template.xml with some columns, content types and list. I have a lookup column call Fase that comes of the Fase list and this list has a Orden Column. I need to add Orden field as an additional lookup column.

template.xml

<Field ID="{A35B465E-E95A-436A-8FCD-A3B3F601D2C5}" Type="Lookup" Name="Fase" DisplayName="Fase" Group="IniciativasEstrategicas" Required="FALSE" EnforceUniqueValues="FALSE" List="Lists/Fases" ShowField="NombreFase" UnlimitedLengthInDocumentLibrary="FALSE" RelationshipDeleteBehavior="None"/>
<Field ID="{E7B67252-CF32-46DF-A90D-4A3D7F62464A}" Type="Lookup" Name="OrdenFase" DisplayName="Orden Fase" Group="IniciativasEstrategicas" ReadOnly="TRUE" Required="FALSE" EnforceUniqueValues="FALSE" List="Lists/Fases" ShowField="Orden" FieldRef="A35B465E-E95A-436A-8FCD-A3B3F601D2C5" UnlimitedLengthInDocumentLibrary="FALSE" RelationshipDeleteBehavior="None"/>

The result of this xml is an additional column without list associate to it

3

You can use the AddFieldAsXml method (see the MSDN):

ClientContext clientContext = new ClientContext(siteUrl);
Web site = clientContext.Web;
var targetList = site.Lists.GetByTitle("YourTargetList");
var relatedList = site.Lists.GetByTitle("FaseList");
var fields = targetList.Fields;

clientContext.Load(relatedList);
clientContext.ExecuteQuery();

var fields = targetList.Fields;
string fieldSchema = string.Format("<Field ID=\"{0}\" Type=\"Lookup\" Name=\"OrdenFase\" DisplayName=\"Orden Fase\" Group=\"IniciativasEstrategicas\" ReadOnly=\"TRUE\" List=\"{1}\" ShowField=\"Orden\" FieldRef=\"A35B465E-E95A-436A-8FCD-A3B3F601D2C5\" />",
 Guid.NewGuid(), relatedList.Id);

 fields.AddFieldAsXml(fieldSchema, true, AddFieldOptions.AddToDefaultContentType);
 clientContext.Load(fields);
 clientContext.ExecuteQuery();
1

Actually in the dev brach works perfectly!

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.