Results 1 to 7 of 7

Thread: Case Emailing

  1. #1
    MUrick is offline Junior Member
    Join Date
    Jun 2006
    Posts
    3

    Default Case Emailing

    My Company is currently Running Sugar Open Source on CentOS Build and we are in the process of testing the case management system. I have a few Qurestions about e-mailnig within sugar in reference to cases.

    First does anyone know if it possible to have sugar automatically send out an e-mail to the primary contact for a case when it is closed.

    Second when you create an e-mail template, a person is able to enter various fields from inside of sugar for account, leads, and contacts. but one thing I have noticed is that a person is not able to enter any data from cases. is there any way to do this?

    Thanks in advance for any help
    Last edited by MUrick; 2006-08-07 at 08:31 PM.

  2. #2
    sugarchris's Avatar
    sugarchris is offline Sugar Community Member
    Join Date
    Sep 2005
    Location
    San Francisco, CA
    Posts
    861

    Default Re: Case Emailing

    Since you're running the OS version, I can't just say "Use workflow!"

    The code you're looking to customize will be found in ./modules/Cases/Save.php

    Basically, you feel for the "Closed" flag, and then do some stuff, a la:
    PHP Code:
     if($focus->status == 'Closed') {
         
    // do some stuff here
     
     

    The "stuff" part is up to you, but a simple email alert, for cases in particular would be like:
    PHP Code:
     $email = new Email();
     
    $email->type 'out';
     
    $email->name "The Subject";
     
    $email->description "The body text goes here.";
     
    $email->to_addrs_arr $email->parse_addrs(""$focus->id$focus->first_name." ".$focus->last_name$focus->email1);
     
    $email->from_addr $current_user->email1;
     
    // link to case
     
    $email->load_relationship("cases");
     
    $email->add($focus->id);
     
    // make it the primary link
     
    $email->parent_type 'aCase';
     
    $email->parent_id $focus->id;
     
    // link the CSR
     
    $email->load_relationship("users");
     
    $email->users->add($current_user->id);
     
     
    // save & send
     
    $email->save();
     
    $email->send(); 
    Notice I said "Like" - you'll have to do the footwork to get the contact from the case, but it's fairly straightforward; just follow the above examples.


    The second question is difficult to answer. It requires a pretty deep understanding of Sugar's class system. If you want to attempt this customization, you'll be spending a lot of time in the modules/EmailTemplates module.

    The rule of thumb is to do exactly what is being done for Contacts/Leads and just substitute "Cases" in.

    If you do get it working, you should start a SugarForge project for this - it's not the first time I've heard this asked for as a feature.

  3. #3
    dstrickler is offline Sugar Community Member
    Join Date
    Mar 2006
    Posts
    77

    Default Re: Case Emailing

    We are using the Pro version, and I agree with Chris, it's the easy way to go on notification systems. It still have some small bugs that they are working out, but on the whole it can get you out of writing lots of code with just a few clicks.


    One of the reasons we decided to go with Pro was for the workflow.
    Dave Strickler
    MailWise LLC
    www.mailwise.com
    Intelligent Email Protection, compatible with Sugar




  4. #4
    Nuno is offline Sugar Community Member
    Join Date
    Mar 2007
    Posts
    12

    Default Re: Case Emailing

    Hi sugarchris,

    I added your code to /modules/cases/save.php but no email was sent to customer and i really do not know what to do to get it work.

    Could you help me, please?

    Thanks in advance for your support

    I am using sugarOS 4.5.1d


    Quote Originally Posted by sugarchris
    Since you're running the OS version, I can't just say "Use workflow!"

    The code you're looking to customize will be found in ./modules/Cases/Save.php

    Basically, you feel for the "Closed" flag, and then do some stuff, a la:
    PHP Code:
     if($focus->status == 'Closed') {
         
    // do some stuff here
     
     

    The "stuff" part is up to you, but a simple email alert, for cases in particular would be like:
    PHP Code:
     $email = new Email();
     
    $email->type 'out';
     
    $email->name "The Subject";
     
    $email->description "The body text goes here.";
     
    $email->to_addrs_arr $email->parse_addrs(""$focus->id$focus->first_name." ".$focus->last_name$focus->email1);
     
    $email->from_addr $current_user->email1;
     
    // link to case
     
    $email->load_relationship("cases");
     
    $email->add($focus->id);
     
    // make it the primary link
     
    $email->parent_type 'aCase';
     
    $email->parent_id $focus->id;
     
    // link the CSR
     
    $email->load_relationship("users");
     
    $email->users->add($current_user->id);
     
     
    // save & send
     
    $email->save();
     
    $email->send(); 
    Notice I said "Like" - you'll have to do the footwork to get the contact from the case, but it's fairly straightforward; just follow the above examples.


    The second question is difficult to answer. It requires a pretty deep understanding of Sugar's class system. If you want to attempt this customization, you'll be spending a lot of time in the modules/EmailTemplates module.

    The rule of thumb is to do exactly what is being done for Contacts/Leads and just substitute "Cases" in.

    If you do get it working, you should start a SugarForge project for this - it's not the first time I've heard this asked for as a feature.

  5. #5
    sugarchris's Avatar
    sugarchris is offline Sugar Community Member
    Join Date
    Sep 2005
    Location
    San Francisco, CA
    Posts
    861

    Default Re: Case Emailing

    If you've copied/pasted the code I wrote above into your modules/Cases/Save.php file, and you do not get a sent message, the debugging would start with the following steps.
    0. Save.php is one step in a two-step process. At the bottom, you will see that we redirect you to the DetailView of the just-saved case. This is to prevent refreshes from resubmitting. This also means that any debug output will be lost unless you put a die(); statement after.

    1. Is your user's outbound email set up correctly in My Account? This would be true if you can send a basic email out from the Emails module.

    2. Is that code actually getting run. Try var_dump()'ing the value of $focus->status right before the if() block - is the value what you expect?

    3. capture the return of the $email->save() call - it will be a boolean. var_dump() it as well and make sure you get a "true" response.

    4. does the sent-message get saved, do you see it in the Emails module (All Emails)? If not, something is stopping the code execution.

    5. If none of the above work out, you'll have to step-by-step figure out where the failure is. The most complicated code point is the email address (to address) creation. Make sure the value in $email->to_addrs_arr is what you expect (again a var_dump()).

  6. #6
    kkuhl is offline Sugar Community Member
    Join Date
    Jun 2007
    Posts
    13

    Default Re: Case Emailing

    Chris, I have a similar problem, however slightly different. I just need to add some code to send an email to a few folks in our office (hardcoded email addys) whenever a new case is created. I was looking for the right place to place the code but I'm a little confused as to where the information actually begins 'saving'. I looked at Save.php and after reading this post I assume thats where this needs to go. What should I feel for to determine when a case has just been created? I thought it would be status = new but there can be many different options for that field on a new Case. Can you help me?

  7. #7
    sugarchris's Avatar
    sugarchris is offline Sugar Community Member
    Join Date
    Sep 2005
    Location
    San Francisco, CA
    Posts
    861

    Default Re: Case Emailing

    Quote Originally Posted by kkuhl
    Chris, I have a similar problem, however slightly different. I just need to add some code to send an email to a few folks in our office (hardcoded email addys) whenever a new case is created. I was looking for the right place to place the code but I'm a little confused as to where the information actually begins 'saving'. I looked at Save.php and after reading this post I assume thats where this needs to go. What should I feel for to determine when a case has just been created? I thought it would be status = new but there can be many different options for that field on a new Case. Can you help me?
    Your best bet for this kind of customization is to use the SugarBean's logic hooks. These hooks allow you to run additional code for common bean states (save, after save, before delete, etc).

    Here's the current wiki article on how to use this mechanism:
    WIKI Article

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •