private static void SaveAttributeValue( Rock.Model.Workflow workflow, string key, string value, FieldTypeCache fieldType, RockContext rockContext, Dictionary<string, string> qualifiers = null ) { if (workflow.Attributes.ContainsKey(key)) { workflow.SetAttributeValue( key, value ); } else { // If workflow attribute doesn't exist, create it // ( should only happen first time a background check is processed for given workflow type) var attribute = new Rock.Model.Attribute(); attribute.EntityTypeId = workflow.WorkflowType.TypeId; attribute.EntityTypeQualifierColumn = "WorkflowTypeId"; attribute.EntityTypeQualifierValue = workflow.WorkflowTypeId.ToString(); attribute.Name = key.SplitCase(); attribute.Key = key; attribute.FieldTypeId = fieldType.Id; if ( qualifiers != null ) { foreach( var keyVal in qualifiers ) { var qualifier = new Rock.Model.AttributeQualifier(); qualifier.Key = keyVal.Key; qualifier.Value = keyVal.Value; attribute.AttributeQualifiers.Add( qualifier ); } } // Set the value for this action's instance to the current time var attributeValue = new Rock.Model.AttributeValue(); attributeValue.Attribute = attribute; attributeValue.EntityId = workflow.Id; attributeValue.Value = value; new AttributeValueService( rockContext ).Add( attributeValue ); } }
private void CopyAttributes(Rock.Model.Workflow newWorkflow, Rock.Model.WorkflowActivity currentActivity, RockContext rockContext) { if (currentActivity.Attributes == null) { currentActivity.LoadAttributes( rockContext ); } if (currentActivity.Workflow.Attributes == null) { currentActivity.Workflow.LoadAttributes( rockContext ); } // Pass attributes from current Workflow to new Workflow. foreach (string key in currentActivity.Workflow.AttributeValues.Keys) { newWorkflow.SetAttributeValue( key, currentActivity.Workflow.GetAttributeValue( key ) ); } // Pass attributes from current Activity to new Workflow. foreach (string key in currentActivity.AttributeValues.Keys) { newWorkflow.SetAttributeValue( key, currentActivity.GetAttributeValue(key) ); } }