Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at

  • Satpal Gahir 18 posts 87 karma points
    Nov 28, 2019 @ 14:53
    Satpal Gahir

    FieldType.ConvertToRecord Deprecated in Umbraco Forms 8.2?


    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:

    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);
            record.RecordFields.Add(allField.Id, recordField);
            _recordStorage.InsertRecord(record, form);

    Regards, Satpal

  • Satpal Gahir 18 posts 87 karma points
    Nov 28, 2019 @ 15:00
    Satpal Gahir

    Unable to switch this for Umbraco Forms Forum :(

  • Satpal Gahir 18 posts 87 karma points
    Nov 28, 2019 @ 16:32
    Satpal Gahir

    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>();
Please Sign in or register to post replies

Write your reply to: