Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > BizFrom -> Notification e-mail -> run function on value View modes: 
User avatar
Member
Member
eagleag - 10/11/2010 4:24:35 AM
   
BizFrom -> Notification e-mail -> run function on value
hi,
I'm using Notification e-mail layout and one of the fields sent in remail is date of birth.
It is saved in DB as Date & Time (example: 01/02/2010 1:00:00 AM) whcih is great, but
on the email I only want the actual date sent out 01/02/2010.

I tried using inline control and custom macros but cant get it to work.
How can I achieve this?

THANKS :)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/11/2010 5:29:41 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
Hi,

Have you tried to use custom macro in combination with BoundColumn to achieve your goal?

mName is the name of your datetime column.


BoundColumn col = new BoundColumn();
col.DataField = mName;
col.DataFormatString = "{0:d}";


Could you please show us the code of your custom macro in case of troubles?

Best regards,
Ivana Tomanickova

User avatar
Member
Member
eagleag - 10/11/2010 6:27:16 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
after creating the custom macros code, how to i write the macros iteself?

This is the value when displaying in notifacation Em-mail $$value:DateOfBirth$$.

lets say that the custom macros name is showonlyDate, how would I write the code that "sends" original value to code?

thanks :)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/12/2010 5:58:39 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
Hi,

How to write a custom macro is described here:
http://devnet.kentico.com/docs/devguide/appendix_a___macro_expressions.htm

Possible solution depends on where the value of dateofbirth is stored. If it is saved for example in the subscriber table, you could get it in the custom macro from the sender object:
public static string ResolveCustomMacro(MacroResolver sender, string expression, out bool match)
{
CMS.Newsletter.Subscriber iSubscriber = sender.SourceData[2] as CMS.Newsletter.Subscriber;
string iEmail = iSubscriber.SubscriberEmail;

// the rest of custom macro code

}

If the value is stored somewhere else, you need to get it via API in the code of custom macro and return requested value according to it.

Best regards,
Ivana Tomanickova

User avatar
Member
Member
eagleag - 10/12/2010 7:30:34 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
thakn for the reply but I still don;t understand how (after creating the custom macros)
I use the macros in the area I have to write in cmsdesk.

It's for a BizFrom -> Notification e-mail - so how would this macros look?

this is how a value is shown $$value:DateOfBirth$$
how would the new macros look? $myMacros|date(DD mm YY)$

THANKS :)

User avatar
Kentico Developer
Kentico Developer
kentico_ivanat - 10/12/2010 8:03:10 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
Hi,
You can insert following value into BizForm -> Notification e-mail (if you check Use custom layout):

{% ProcessCustomMacro("someexpression", "") %}

This expresion will be resolved to "Resolved expression" string if following code is defined in the file: ~\App_Code\Global\CMS\CMSCustom.cs


public static string ResolveCustomMacro(MacroResolver sender, string expression, out bool match)
{
match = false;
string result = expression;

// Add your custom macro evaluation

switch (expression.ToLower())
{
case "someexpression":
match = true;
result = "Resolved expression";
break;
}

return result;
}


Best regards,
Ivana Tomanickova

User avatar
Member
Member
eagleag - 10/12/2010 11:07:43 AM
   
RE:BizFrom -> Notification e-mail -> run function on value
Thanks ivanat :)

this is what I did:

BizFrom -> Notification e-mail:
{% ProcessCustomMacro("mycase"|(default), "|(defaultimplicit)") %}

CODE:

string[] temp = expression.Split('|');
expression = temp[0];


switch (expression.ToLower())
{
case "mycase":
match = true;
DateTime dt;
dt = Convert.ToDateTime(temp[1].ToString());
result = dt.Month + "/" + dt.Day + "/" + dt.Year;

break;
}



Thanks for your help :)