Create a Choice type Site Column in SharePoint Hosted Add-in using Visual Studio

This SharePoint tutorial, we will show how to create choice type site column and add mapping inside SharePoint hosted add-in in SharePoint Online.

We will do this inside a SharePoint hosted add-in using visual studio 2017/2015 in SharePoint Online.

Create a Choice type Site Column in SharePoint Hosted Apps using Visual Studio

Now follow the below steps to add a site column of type choice programmatically in SharePoint.

Right click on Visual Studio 2017/2015 -> Add -> New Item…

Then in the Add New Item dialog box, choose Site Column and give a name and then click on Add.

By default SharePoint will add Text type column.

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{d8102081-02cf-48df-a41f-a4c9b914b313}"
Name="TrainingCourses"
DisplayName="Training Courses"
Type="Text"
Required="FALSE"
Group="Custom Site Columns">
</Field>
</Elements>

To add choice column, we can change the Type to Choice and then we can add the choices inside <CHOICES> </CHOICES>.

Similarly to add mapping values, we can inside Mapping attribute and to add a default value, we can add inside <Default></Default> attribute.

The full code looks like below:

<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Field
ID="{d8102081-02cf-48df-a41f-a4c9b914b313}"
Name="TrainingCourses"
DisplayName="Training Courses"
Type="Choice"
Required="FALSE"
Group="Custom Site Columns">
<CHOICES>
<CHOICE>SharePoint 2016</CHOICE>
<CHOICE>SharePoint 2013</CHOICE>
<CHOICE>SharePoint 2010</CHOICE>
<CHOICE>SharePoint Online</CHOICE>
<CHOICE>Office 365</CHOICE>
<CHOICE>Microsoft Azure</CHOICE>
</CHOICES>
<MAPPINGS>
<MAPPING Value="1">SharePoint 2016</MAPPING>
<MAPPING Value="2">SharePoint 2013</MAPPING>
<MAPPING Value="3">SharePoint 2010</MAPPING>
<MAPPING Value="4">SharePoint Online</MAPPING>
<MAPPING Value="5">Office 365</MAPPING>
<MAPPING Value="6">Microsoft Azure</MAPPING>
</MAPPINGS>
<Default>SharePoint Online</Default>
</Field>
</Elements>

You may like following SharePoint hosted add-in tutorial:

I hope this will be helpful to create a choice type site column programmatically using jsom in SharePoint hosted add-in.

>