Author Topic: Adding the address of the target to the mail sent with Activity  (Read 1268 times)

Offline Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1257
  • Karma: 44
    • EE-atWork
  • CiviCRM version: from 3.3.5 to 4.3
  • CMS version: Drupal 6.20 and Drupal 7
  • MySQL version: 5.5.29-0ubuntu0.12.10.1
  • PHP version: PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli)
Adding the address of the target to the mail sent with Activity
« on: December 21, 2011, 11:24:43 am »
Bit of a challenge, which I do have a solution for but it is a bit hackish....so any more structured alternative is very welcome!

The use case: we have guys out in our neighborhood meeting with our customers and doing all sort of stuff. Part of what they do is triggered from the activities they are assigned in CiviCRM. They receive an email, which they can see on their mobile phones. For example, the back office receives a call from a customer saying he needs someone to come over and inspect leakage in the house. The technical guy receives the email and could go to the customer concerned without getting back to the office. However, it would be a huge improvement if they would also see the address of the customer, which is not in the standard message template.

So I thought I would solve it by changing the standard message template Cases - Send Copy of an Activity. I would have to add a token to hold the address of the customer, which I could do with the token hook. If I then use the tokenValue hook however, I only get the contactId of the assignee id and NOT the id of the customer involved. What I am going to do now is use the API to retrieve all the acitivities of the assignee and assume I need the latest activity, and retrieve the address of the first target.
That will probably work for my specific need, but it is a little hackish.............any better suggestions?
 
Make sure you check the latest Make It Happen initiatives!

Online Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 14732
  • Karma: 440
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: Adding the address of the target to the mail sent with Activity
« Reply #1 on: December 21, 2011, 05:33:23 pm »

Hey Erik:

Can u investigate and submit a patch that assigns the target_contact_ids, names to the template.

The relevant code is:

CRM/Activity/Form/Activity.php, near line 1048. You might wnt to get all target ids nd names in one call
CRM/Case/BAO/Case.php - function sendActivityCopy

lobo
Found this reply helpful? Contribute NOW and help improve CiviCRM with the Make it Happen! initiative.

Offline xavier

  • Forum Godess / God
  • I’m (like) Lobo ;)
  • *****
  • Posts: 3732
  • Karma: 134
    • Tech To The People
  • CiviCRM version: yes probably
  • CMS version: drupal
Re: Adding the address of the target to the mail sent with Activity
« Reply #2 on: December 26, 2011, 06:42:08 am »
And with the ids of the assigned, you can use the smarty {crmAPI} in the mail template I'm quite sure.


Offline Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1257
  • Karma: 44
    • EE-atWork
  • CiviCRM version: from 3.3.5 to 4.3
  • CMS version: Drupal 6.20 and Drupal 7
  • MySQL version: 5.5.29-0ubuntu0.12.10.1
  • PHP version: PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli)
Re: Adding the address of the target to the mail sent with Activity
« Reply #3 on: December 27, 2011, 01:03:22 am »
Lobo, will have a look at the best solution and raise an issue for it.
X, obviously the API can do all sorts of magic almost everywhere :-), and will certainly use the {crmAPI} in the mail template once I have the targetted Ids.
Make sure you check the latest Make It Happen initiatives!

Offline totten

  • Administrator
  • I post frequently
  • *****
  • Posts: 203
  • Karma: 17
Re: Adding the address of the target to the mail sent with Activity
« Reply #4 on: December 29, 2011, 11:05:00 pm »
1) I'll second (or third) the point about using Smarty and APIv3 instead of the token hooks. It's more flexible and (when there are multiple entities floating around) clearer.

2) When using "Scheduled Reminders" to generate per-activity emails, I encountered a similar issue. I initially tried using {crmAPI} to lookup target/assignee contacts based on the activity_id, but that proved cumbersome. (I needed to do multiple lookups -- and to use the same sequence of lookups in several different email templates). This led to a hack called {simpleActivityContacts}, as in:

Code: [Select]
{simpleActivityContacts activity_id=$activity.activity_id}
Hello, {$assignee.display_name}, you should talk to {$target.display_name}.

That particular Smarty function probably shouldn't be publicized, but it may be an interesting example.

3) If the activities are managed through CiviCase, you might use client_id in lieu of target_contact_id or activity_id.

Offline Erik Hommel

  • Forum Godess / God
  • I live on this forum
  • *****
  • Posts: 1257
  • Karma: 44
    • EE-atWork
  • CiviCRM version: from 3.3.5 to 4.3
  • CMS version: Drupal 6.20 and Drupal 7
  • MySQL version: 5.5.29-0ubuntu0.12.10.1
  • PHP version: PHP 5.3.10-1ubuntu3 with Suhosin-Patch (cli)
Re: Adding the address of the target to the mail sent with Activity
« Reply #5 on: December 30, 2011, 03:01:41 am »
@totten: I will have to do a small change to the BAO first to pass on the targetId's concerned first, thanks for the Smarty function :-)
Make sure you check the latest Make It Happen initiatives!