CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Default value for tokens
Pages: [1]

Author Topic: Default value for tokens  (Read 2187 times)

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Default value for tokens
March 21, 2011, 07:04:33 am
We have recently run into an issue where we need to set a default value for mail merge tokens such as

First Name,
Last Name,
etc.

sometimes the contact does not have a value for the contact so we would like to specify a default value for these fields when we insert the token.

Currently, the most viable way of doing it is using a hook mentioned in this blog post:

http://civicrm.org/node/637

From an old documentation below (which was outdated), it stated that specifying something like {token | default_value} would merge in a default value if the token is empty.

http://wiki.civicrm.org/confluence/display/CRMDOC33/Mail+Generator#MailGenerator-Nullvaluesanddefaults

Although this method did not work with the 3.3 branch, I like the approach better. I think there are enough interests out there to build this into a core feature.


I'd like to get started by looking at implementing the second way with some simple (scalar valued) tokens first and then perhaps creating more complicated syntax for other token merges.


Any comments and feedbacks are much appreciated!



Cheers!

lcdweb

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1620
  • Karma: 116
    • www.lcdservices.biz
  • CiviCRM version: many versions...
  • CMS version: Joomla/Drupal
  • MySQL version: 5.1+
  • PHP version: 5.2+
Re: Default value for tokens
March 21, 2011, 07:15:57 am
hey Chang,
+1 for passing the option through the token instance.

we had some discussion on IRC a while back about how nice it would be if we could pass parameter options to tokens -- of which default values could be one "standard" option. in my case i have a custom token that aggregates contributions for a contact for the year so it can be inserted in a letter. but currently i need to tokenize it on a per-year basis (aggregate_contribs_2010). i would love to be able to define and pass the year as a parameter so that I can have a generic token.

just food for thought if you go down that road.
support CiviCRM through 'make it happen' initiatives!
http://civicrm.org/mih

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Default value for tokens
March 21, 2011, 08:14:51 am

hey chang:

a couple of thoughts and comments:

1. Can u make the "default" parameter passing generic so we can introduce other parameters as needed. We might want to go with a "name=value" type mechanism. If you can build this into the token parser that would be great and help follow on projects

2. For default, this is not gonna be an issue. But we need to avoid making any additional DB calls in the core inner loop of delivering email. Slows down mail delivery!

3. Make sure we pass these parameters onto the hook. Since we are doing this, we should also tell the hook the tokens we are interested in, so it can ignore the request if needed

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xcf33

  • I post frequently
  • ***
  • Posts: 181
  • Karma: 7
  • CiviCRM version: 3.3.2
  • CMS version: Drupal 6.19/6.20
  • MySQL version: 5.x
  • PHP version: 5.2.6
Re: Default value for tokens
March 21, 2011, 11:16:58 am
I'm probably going to start by going after the default value (simple scalar values to replace common contact tokens)

Lobo, what's the best practice for doing this again that will not affect the performance for mailing?


I want to have that implemented before looking at passing params to the tokens. That we might have to have a more in-depth discussions and maybe get Brian involved :p

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Default value for tokens
March 21, 2011, 12:17:56 pm

a few things:

1. if you are not calling the DB, it should not affect the speed significantly.

2. Make sure u pass the default values to the hook also

3. for the main civimail workflow, changing it in the getDetails function is probably the most efficient (and minimal code changes). Will also need to fix here: CRM/Mailing/BAO/Mailing.php (line 1325).

ping me on irc if needed and we can discuss details

lobo

A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 4453
  • Karma: 161
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Default value for tokens
March 21, 2011, 02:21:01 pm
One issue that slows down the sending is that we don't know on the token hook if the token is used in the email.

Providing to the hook a list of token existing in the mailing would speed up things and solve lobo's point about DB calls ?

X+
-Hackathon and data journalism about the European parliament 24-26 jan. Watch out the result

bcobin

  • I post frequently
  • ***
  • Posts: 337
  • Karma: 9
    • InterCreative Media
  • CiviCRM version: 4.3.3
  • CMS version: Drupal 7.22
  • MySQL version: 5.5.9
  • PHP version: 5.3
Re: Default value for tokens
July 08, 2011, 06:31:04 pm
Sorry about resurrecting this thread, but this seems like the most recent discussion of this issue - it's an issue that it seems a lot of users are running into. Sending an email that's addressed to Dear , just looks bad. Considering all the great work that's been done on CiviMail, it's a real shame to make such an inelegant and "computer-y" impression right at the beginning of a message.

Not being a developer, I'm not sure what to do with the code from http://civicrm.org/node/637 or if it's even still relevant for 3.4.

And http://wiki.civicrm.org/confluence/display/CRMDOC33/Mail+Generator#MailGenerator-Nullvaluesanddefaults doesn't work for 3.4 either, unfortunately.

I'm assuming future developments will be on this thread - please correct me if there's somewhere else I should be looking.

Otherwise, any guidance much appreciated - thanks!

« Last Edit: July 08, 2011, 06:32:41 pm by bcobin »

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Default value for tokens
July 09, 2011, 01:28:40 am

I dont think anyone has made any further progress with this.

I do think that the token system needs some work and allow parameters to be sent so we can:

1. send in default values
2. send in arguments to filter the values
3. send in formatting commands

hopefully someone will make this happen in the next release (or two or three)

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Developer Discussion (Moderator: Donald Lobo) »
  • Default value for tokens

This forum was archived on 2017-11-26.