Skip to content

Instantly share code, notes, and snippets.

@jonathanread
Created May 14, 2019 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanread/4813f6bf1a7f611f8ff737e18b8ccb82 to your computer and use it in GitHub Desktop.
Save jonathanread/4813f6bf1a7f611f8ff737e18b8ccb82 to your computer and use it in GitHub Desktop.
This Calculated field is intended to return the string values of a choices field on a content item. Follow instructions here to add the property to your web service. You will need to replace 'Features' with your Property name. https://www.progress.com/documentation/sitefinity-cms/for-developers-custom-calculated-properties
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Telerik.Sitefinity.Data;
using Telerik.Sitefinity.DynamicModules.Model;
using Telerik.Sitefinity.Model;
using Telerik.Sitefinity;
using Telerik.Sitefinity.Web.Services.Extensibility;
namespace SitefinityWebApp.Helpers
{
public class CustomChoicesCalculatedField : CalculatedProperty
{
/// <summary>
/// What type of data is being returned, must be a simple type or something that is already in the service or marked with [DataContract]
/// </summary>
public override Type ReturnType
{
get
{
return typeof(ChoiceOption[]);
}
}
/// <summary>
/// Returns Choice option for Choices fields on the Jobs Dynamic Module
/// </summary>
/// <param name="items">Data beeing returned by the oData service</param>
/// <param name="manager">Current Manager from the service</param>
/// <returns></returns>
public override IDictionary<object, object> GetValues(IEnumerable items, IManager manager)
{
var ret = new Dictionary<object, object>();
foreach (IDataItem item in items)
{
var dynamicContent = item as DynamicContent;
var choices = dynamicContent.GetValue<ChoiceOption[]>("Features");
if (choices != null)
{
ret.Add(item, choices);
}
}
return ret;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment