Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Macro in BizForm To E-mail View modes: 
User avatar
Member
Member
ctaleck IPAGlobal - 4/16/2009 4:42:54 PM
   
Macro in BizForm To E-mail
Under CMS Desk > Tools > BizForms > Notification e-mail the To e-mail: apparently can contain a macro as indicated by this error when I leave it blank.

Please enter a valid e-mail to address or macro.

So I want to try to dynamically assign the To e-mail by trying:

{%Email_Address%}

where Email_Address is a field from a custom document type I created (which my BizForm is on). It is not working in this case.

Am I attempting to do something that is possible? What macros are valid in this context?

User avatar
Kentico Developer
Kentico Developer
kentico_martind - 4/22/2009 8:05:22 AM
   
RE:Macro in BizForm To E-mail
Hello,

Unfortunately, you can specify only columns of BizForm to get value from this column.

You could eventually try procedure bellow to pass value from field of document type to field of BizForm:

1) Create some another field for BizForm and set it not to be displayed in public form

2) Implement OnBeforeSave event handler (similarly as described at http://www.kentico.com/docs/devguide/modifying_the_code_of_standard_web_parts.htm) and in this handler you can add value from custom field of document type into new field of BizForm. Please see sample code bellow:

this.BizFormNew.BasicForm.DataRow["NameOfBizFormField"] =
CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("NameOfDocumentTypeField");

Best Regards,

Martin Dobsicek

User avatar
Member
Member
ctaleck IPAGlobal - 4/23/2009 1:52:04 PM
   
RE:Macro in BizForm To E-mail
Thank you for sending me in the right direction with this.

I had to use the OnBeforeSave event (as opposed to the OnAfterSave) to get it to work.

    protected void viewBiz_OnBeforeSave()
{
// put into the form a field containing the e-mail address of the current contact from custom_contact table
this.viewBiz.BasicForm.DataRow["EmailToContact"] = CMS.CMSHelper.CMSContext.CurrentDocument.GetValue("Email_Address");
}


In the CMS Desk > Tools > BizForms > [Choose Form] > Notification e-mail > To e-mail field I inserted this macro {%EmailToContact%} which is the extra field I added to my form fields.

One thing to note: I was not able to uncheck the Show on public form in the Field definition as it removed the field completely from the form. I instead had to set the Caption style and the Input style to display:none so that the field was available when I copied the value into it.