Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
Hi,
I have been trying to save a form state to record in a multi step form, however, when i try anything to convert the FormState Array Object, i cannot get the object to assign to the RecordField.Values.
The original code posted on here:
https://our.umbraco.com/forum/umbraco-forms/87608-multi-page-form-save-data#comment-314525
I've had to rejig the code, so that DependencyInjection could occur:
private IRecordService _recordService; private IRecordStorage _recordStorage; private DistributedCache _distributedCache; private IFormStorage _formStorage; private FieldCollection _fieldCollection; private IFieldTypeStorage _fieldTypeStorage; private IFieldPreValueSourceService _fieldPreValueSourceService; private IFieldPreValueSourceTypeService _fieldPreValueSourceTypeService; private IUmbracoContextAccessor _umbracoContextAccessor; public FormsController(DistributedCache distributedCache, IFormStorage formStorage,IRecordService recordService, IRecordStorage recordStorage, FieldCollection fieldCollection, IFieldTypeStorage fieldTypeStorage, IFieldPreValueSourceService fieldPreValueSourceService, IFieldPreValueSourceTypeService fieldPreValueSourceTypeService, IUmbracoContextAccessor umbracoContextAccessor) : base(distributedCache, formStorage, recordStorage, recordService, fieldCollection, fieldTypeStorage, fieldPreValueSourceService, fieldPreValueSourceTypeService, umbracoContextAccessor) { _recordService = recordService; _recordStorage = recordStorage; _distributedCache = distributedCache; _formStorage = formStorage; _fieldCollection = fieldCollection; _fieldTypeStorage = fieldTypeStorage; _fieldPreValueSourceService = fieldPreValueSourceService; _fieldPreValueSourceTypeService = fieldPreValueSourceTypeService; _umbracoContextAccessor = umbracoContextAccessor; }
Then the IRecordService and IRecordStorage interfaces are available to the controller.
If anyone can help solve this:
Record record = new Record(); record = BaseGetRecord(model.RecordId, form); foreach (Field allField in form.AllFields) { object[] objArray = new object[0]; //This doesnt work! object[] answerValues = objArray.ToArray(); // Old code was: object[] answerValues = allField.FieldType.ConvertToRecord(allField, objArray, context.HttpContext).ToArray(); if (state != null && state.ContainsKey(allField.Id.ToString())) { objArray = state[allField.Id.ToString()]; } if (!record.RecordFields.ContainsKey(allField.Id)) { RecordField recordField = new RecordField(allField); recordField.Values.AddRange(*answerValues*); record.RecordFields.Add(allField.Id, recordField); _recordStorage.InsertRecord(record, form); } }
Regards, Satpal
Unable to switch this for Umbraco Forms Forum :(
It think i figured it out. There is a FieldType type which can do this. Its no longer in the Field.FieldType property. You get the FieldType by Id:
FieldType fieldTypeByField = this._fieldTypeStorage.GetFieldTypeByField(allField); objArray = fieldTypeByField.ConvertToRecord(allField, objArray, context.HttpContext).ToArray<object>();
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
FieldType.ConvertToRecord Deprecated in Umbraco Forms 8.2?
Hi,
I have been trying to save a form state to record in a multi step form, however, when i try anything to convert the FormState Array Object, i cannot get the object to assign to the RecordField.Values.
The original code posted on here:
https://our.umbraco.com/forum/umbraco-forms/87608-multi-page-form-save-data#comment-314525
I've had to rejig the code, so that DependencyInjection could occur:
Then the IRecordService and IRecordStorage interfaces are available to the controller.
If anyone can help solve this:
Regards, Satpal
Unable to switch this for Umbraco Forms Forum :(
It think i figured it out. There is a FieldType type which can do this. Its no longer in the Field.FieldType property. You get the FieldType by Id:
is working on a reply...