Hi all,
I created a Custom Scheduled Task that connects to an API and gathers some data, periodically, among which the Caption and ValidationErrorMessage for given fields of a form. Now, ther reasons I must do it are a lot, I don't want to get in details. That said, I tried to find documentation on how to save a property programmatically and I'm still not able to.
Currently, the core part of my code that should update a field given his formfieldname looks like this:
private void SetFormFieldText(string formfieldname, string caption_text, string validation_text) { BizFormInfo formObject = BizFormInfoProvider.GetBizFormInfo("MyCustomForm", SiteContext.CurrentSiteID); DataClassInfo dci = DataClassInfoProvider.GetDataClassInfo(formObject.FormClassID); if (dci != null) { FormInfo fi = new FormInfo(dci.ClassFormDefinition); if(fi != null) { FormFieldInfo ffi = fi.GetFormField(formfieldname); if (ffi!=null) { ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption,caption_text); ffi.SetPropertyValue(FormFieldPropertyEnum.ValidationErrorMessage,validation_text); fi.UpdateExistingFields(fi); //saving? //fi.UpdateFormField(formfieldname,ffi); //tryed this, too } } } }
but neither using UpdateExistingFields or UpdateFormField (that I'm sure are reached and executed) I can trig the saving of those set properties. Using SQL Profiler, I can't see any update on the DB at all.
What's the right way to save changes made on a custom form using SetPropertyValue on a field, programmatically?
I'm using Kentico 9.
Thanks, Fabio
Hi, UpdateExistingFields and UpdateFormField change only form object values in memory and do not modify record in DB. Try to save DataClassInfo object:
UpdateExistingFields
UpdateFormField
DataClassInfo
fi.UpdateExistingFields(fi); ... dci.ClassFormDefinition = fi.GetXmlDefinition(); DataClassInfoProvider.SetDataClassInfo(dci); // or dci.Update()
Hi Fabio,
You can follow this which describe how to work with form data using the API.
Thanks I thought the same, and I was exactly looking for a way to persist it! It works!
Arun, that link explains how to work with the data, not the structure of the form as I asked.
Thank yo all anyway, I solved it!
Please, sign in to be able to submit a new answer.