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:
- Display List items in HTML Table using JSOM in SharePoint Hosted App
- Bind SharePoint Online Host Web List Data to Dropdownlist in SharePoint Hosted Add-in
- Error occurred in deployment step ‘Install SharePoint Add-in’: The remote server returned an error: (503) Server unavailable
- Create Site Column, Content type and List in SharePoint Hosted Appa or Add-in
- Error occurred in deployment step ‘Install SharePoint Add-in’: An instance of this App already exists at the specified location.
- there was a problem with activating the app web definition cannot complete this action SharePoint Online
- Provider Hosted App in SharePoint Online using Visual Studio 2017
- SharePoint online Remove app using PowerShell
- The page you selected contains a list that does not exist. It may have been deleted by another user error in SharePoint Add-in
- you are being redirected to the following URL that was not registered as the app launch URL
- Error occurred in deployment step Install App for SharePoint: Sideloading of apps is not enabled on this site
- Create remote event receiver in SharePoint Online step by step tutorial
I hope this will be helpful to create a choice type site column programmatically using jsom in SharePoint hosted add-in.
I am Bijay from Odisha, India. Currently working in my own venture TSInfo Technologies in Bangalore, India. I am Microsoft Office Servers and Services (SharePoint) MVP (5 times). I works in SharePoint 2016/2013/2010, SharePoint Online Office 365 etc. Check out My MVP Profile.. I also run popular SharePoint web site EnjoySharePoint.com