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);
//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.
UpdateExistingFields and UpdateFormField change only form object values in memory and do not modify record in DB. Try to save DataClassInfo object:
dci.ClassFormDefinition = fi.GetXmlDefinition();
DataClassInfoProvider.SetDataClassInfo(dci); // or dci.Update()
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!
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.