Developer forum

Forum » Development » FormSaveProvider - Change values on Save

FormSaveProvider - Change values on Save

Diogo Lino
Reply

Hello,

 

On a custom FormSaveProvider I'm trying to save a generated value on the form table. I've created the form field and using the parameter "form" or the parameter "keysAndValues" seems not working.

 

        public override bool Save(FormSetting form, Dictionary<string, object> keysAndValues)
        {
                string discountVoucher = GenerateDiscountVoucher();
                form.Fields.FirstOrDefault(p => p.SystemName == "DMForms_RegistoMaquina_DiscountVoucher").Value = discountVoucher;
                form.Fields.FirstOrDefault(p => p.SystemName == "DMForms_RegistoMaquina_DiscountVoucher").Save();
                form.Save();
        }

 

If I use direct access to the database on the FormSaveProvider the changes are stored on the database but are not visible on the confirmation template.

I thought to create an OnGlobalTags subscriber but that way I cannot use that value for the Email sender FormSaveProvider or others.

 

How can I change values during the FormSaveProvider and make it available as tag for the confirmation page and emails sent?

 

Thanks,

Diogo Lino

 


Replies

 
Nicolai Høeg Pedersen
Reply

You probably solved this already...

But it seems like you have 2 calls to form.Fields.FirstOrDefault each of which creates a new instance of the form field. So you set the value in one instance, and create another new instance that you save. You need to save your first instance.

BR Nicolai

 

 

You must be logged in to post in the forum