/// <summary> /// Called bu Umbraco Forms to execute the workflow. /// </summary> /// <param name="record">The record.</param> /// <param name="e">The <see cref="RecordEventArgs"/> instance containing the event data.</param> /// <returns></returns> public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) { try { if (record == null) { return(WorkflowExecutionStatus.Failed); } if (e == null) { return(WorkflowExecutionStatus.Failed); } // Look for a field with the well-known alias "formEntryID" and insert the unique ids in it var updateRecord = false; foreach (var field in record.RecordFields) { if (field.Value.Alias.ToUpperInvariant() == "FORMENTRYID") { field.Value.Values.Clear(); field.Value.Values.Add(e.Form.Id.ToString()); field.Value.Values.Add(record.UniqueId.ToString()); updateRecord = true; break; } } // Update the record with the id if (updateRecord) { using (RecordStorage recordStorage = new RecordStorage()) { // (note recordStorage.UpdateRecord() doesn't work for the first workflow - see http://issues.umbraco.org/issue/CON-1482) record.RecordData = record.GenerateRecordDataAsJson(); if (record.Id > 0) { record = recordStorage.UpdateRecord(record, e.Form); } else { record = recordStorage.InsertRecord(record, e.Form); } } } } catch (Exception exception) { LogHelper.Error <SaveIdAsFieldWorkflow>(exception.Message, exception); return(WorkflowExecutionStatus.Failed); } return(WorkflowExecutionStatus.Completed); }
/// <summary> /// Called bu Umbraco Forms to execute the workflow. /// </summary> /// <param name="record">The record.</param> /// <param name="e">The <see cref="RecordEventArgs"/> instance containing the event data.</param> /// <returns></returns> public override WorkflowExecutionStatus Execute(Record record, RecordEventArgs e) { try { if (record == null) { return(WorkflowExecutionStatus.Failed); } if (e == null) { return(WorkflowExecutionStatus.Failed); } List <Exception> settingsErrors = this.ValidateSettings(); if (settingsErrors != null && Enumerable.Any <Exception>(settingsErrors)) { foreach (Exception exception in settingsErrors) { LogHelper.Error <RetentionAfterSetDateWorkflow>(exception.Message, exception); } return(WorkflowExecutionStatus.Failed); } var days = 0; int.TryParse(Days, out days); var weeks = 0; int.TryParse(Weeks, out weeks); var months = 0; int.TryParse(Months, out months); var years = 0; int.TryParse(Years, out years); // Look for a field with the well-known alias "deleteAfter" and insert a retention date in it var updateRecord = false; foreach (var field in record.RecordFields) { if (field.Value.Alias.ToUpperInvariant() == "DELETEAFTER") { field.Value.Values.Clear(); field.Value.Values.Add(DateTime.Today.AddDays(days).AddDays(weeks * 7).AddMonths(months).AddYears(years).ToString("yyyy-MM-dd", CultureInfo.InvariantCulture)); updateRecord = true; break; } } // Update the record with the retention date if (updateRecord) { using (RecordStorage recordStorage = new RecordStorage()) { // (note recordStorage.UpdateRecord() doesn't work for the first workflow - see http://issues.umbraco.org/issue/CON-1482) record.RecordData = record.GenerateRecordDataAsJson(); if (record.Id > 0) { record = recordStorage.UpdateRecord(record, e.Form); } else { record = recordStorage.InsertRecord(record, e.Form); } } } } catch (Exception exception) { LogHelper.Error <RetentionAfterSetDateWorkflow>(exception.Message, exception); return(WorkflowExecutionStatus.Failed); } return(WorkflowExecutionStatus.Completed); }