SharePoint Online Create choice type site column and add mapping inside SharePoint hosted add-in using visual studio 2015

Here we will see 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 2015 in SharePoint online.

Before reading this, kindly go through the below links:

SharePoint Online Develop SharePoint Hosted Add-in using Visual Studio 2015 Demo

Now follow below steps to add a site column of type choice.

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

Then in the Add New Item dialog box, choose Site Column an 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>.

Read: Remove UserCustomActions from Ribbon in SharePoint list using client side object model csom SharePoint Online

Similarly to add mapping values, we can inside Mapping attribute and to add default value, we ca 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>

Hope this will be helpful.


About Bijay Kumar

I am Bijay from Odisha, India. Currently working with a reputed organization in Bangalore. I am Microsoft Office Servers and Services (SharePoint) MVP (4 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.

View all posts by Bijay Kumar →