/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute(RockContext rockContext, WorkflowAction action, Object entity, out List <string> errorMessages) { errorMessages = new List <string>(); var mergeFields = GetMergeFields(action); var benevolenceRequest = new BenevolenceRequestService(rockContext).Get(GetAttributeValue(action, "BenevolenceRequest", true).AsGuid()); if (benevolenceRequest == null) { var errorMessage = "Benevolence request could not be found."; errorMessages.Add(errorMessage); action.AddLogEntry(errorMessage, true); return(false); } var attribute = AttributeCache.Get(GetAttributeValue(action, "BenevolenceRequestAttribute").AsGuid()); if (attribute == null) { var errorMessage = "Could not find a benevolence attribute matching the one provided."; errorMessages.Add(errorMessage); action.AddLogEntry(errorMessage, true); return(false); } var attributeValue = GetAttributeValue(action, "Value", true).ResolveMergeFields(mergeFields); bool useBlankValues = GetActionAttributeValue(action, "UseBlankValue").AsBoolean(); if (!string.IsNullOrWhiteSpace(attributeValue) || useBlankValues) { benevolenceRequest.LoadAttributes(); Rock.Attribute.Helper.SaveAttributeValue(benevolenceRequest, attribute, attributeValue, rockContext); action.AddLogEntry($"Updated benevolence attribute '{attribute.Name}' to '{attributeValue}'."); } return(true); }
/// <summary> /// Executes the specified workflow. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="action">The action.</param> /// <param name="entity">The entity.</param> /// <param name="errorMessages">The error messages.</param> /// <returns></returns> public override bool Execute( RockContext rockContext, WorkflowAction action, Object entity, out List<string> errorMessages ) { errorMessages = new List<string>(); var mergeFields = GetMergeFields( action ); var benevolenceRequest = new BenevolenceRequestService( rockContext ).Get( GetAttributeValue( action, "BenevolenceRequest", true ).AsGuid() ); if ( benevolenceRequest == null ) { var errorMessage = "Benevolence request could not be found."; errorMessages.Add( errorMessage ); action.AddLogEntry( errorMessage, true ); return false; } var attribute = AttributeCache.Read( GetAttributeValue( action, "BenevolenceRequestAttribute" ).AsGuid() ); if ( attribute == null ) { var errorMessage = "Could not find a benevolence attribute matching the one provided."; errorMessages.Add( errorMessage ); action.AddLogEntry( errorMessage, true ); return false; } var attributeValue = GetAttributeValue( action, "Value", true ).ResolveMergeFields( mergeFields ); bool useBlankValues = GetActionAttributeValue( action, "UseBlankValue" ).AsBoolean(); if ( !string.IsNullOrWhiteSpace( attributeValue ) || useBlankValues) { benevolenceRequest.LoadAttributes(); Rock.Attribute.Helper.SaveAttributeValue( benevolenceRequest, attribute, attributeValue, rockContext ); action.AddLogEntry( $"Updated benevolence attribute '{attribute.Name}' to '{attributeValue}'." ); } return true; }