Last active
June 27, 2019 13:15
-
-
Save merkle-sitecore-gists/4cd2a61bec813ef93df94a96708ce05a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Net; | |
using System.Text.RegularExpressions; | |
using Sitecore.Data.Items; | |
using Sitecore.Rules; | |
using Sitecore.Rules.Actions; | |
namespace TAC.Internet.Web.CMS.Client.Rules.ItemSaved | |
{ | |
public class CopyFieldToField<T> : RuleAction<T> where T : RuleContext | |
{ | |
public string FieldSource | |
{ | |
get; | |
set; | |
} | |
public string FieldTarget | |
{ | |
get; | |
set; | |
} | |
public override void Apply(T ruleContext) | |
{ | |
try | |
{ | |
using (new EditContext(ruleContext.Item, true, false)) | |
{ | |
var item = ruleContext.Item; | |
item.Editing.BeginEdit(); | |
var fieldValue = Regex.Replace(item.Fields[FieldSource].Value, "<.*?>", string.Empty); | |
item.Fields[FieldTarget].Value = WebUtility.HtmlDecode(fieldValue); | |
item.Editing.EndEdit(); | |
} | |
} | |
catch (Exception e) | |
{ | |
log.Warn(e, string.Format("Rule 'Copy Field To Field' threw an exception on item ID {0}", ruleContext.Item.ID)); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment