How to set formula for calculated field in list using the Client Side Object Model in Auto hosted apps?


In this post, we will discuss how to set formula for a calculated field in the list using the Client Side Object Model in Auto hosted apps?


Also you can check out some of the posts on:

Change name of All site content under Site in SharePoint 2010

Disable mobile page redirection for SharePoint 2013

Steps to create private App Catalog and upload our app in SharePoint 2013

Under Page load method write the following code:

var spContext = SharePointContextProvider.Current.GetSharePointContext(Context);

using (var clientContext = spContext.CreateUserClientContextForSPHost())

{

Web web = clientContext.Web;

// Get the list by title

List list = web.Lists.GetByTitle(“ListA”);

// Get the calculated field by title

Field field = list.Fields.GetByTitle(“Calculated”);

// Cast the field

FieldCalculated calculatedField =

clientContext.CastTo<FieldCalculated>(field);

// Set the formula for the calculated field

calculatedField.Formula = “=UPPER([Title])”;

// Update the field

calculatedField.Update();

// Execute the query to the server

clientContext.ExecuteQuery();



}

Check out Best Alternative to InfoPath -> Try Now

You May Also like the Following SharePoint Online Tutorials:

About Navneet Singh

I am Navneet Singh, Working at C3it software solutions pvt. ltd. in Pune. My core skills are SharePoint 2013, Office 365, SharePoint 2010, SharePoint Designer, SharePoint Designer Workflow, Nintex Workflow, Infopath, Webpart, CSOM/SSOM, Power-shell, C#, ASP.NET and SQL Server.

View all posts by Navneet Singh →