Automatic email notification on kreporter assignment

Hi,

We’re using Kreporter v3.1. Do you know how can we get an automatic notification email when a user assigns the report to a different one from himself? In other modules we can do this adding the set_notification_body function in the base class and modifying the notify template’s html, but for Kreporter it is not working. Where should we add the set_notification_body function?

Thanks in advance!

Pat,
in KReporter 3.1. save functionality is called over controller.
Please modify function action_save() in modules/KReports/controller.php by passing true in bean->save().
See my screenshot.SendNotificationOnAssignment
This will trigger send notification logic.

Val

Thank you very much!! It is working now :slight_smile:

Hi again,

I need now to customize the email template that is sent when the report is assigned to another user (different from the one who created it). I have been trying different labels on Sugar’s HTML notify template for several hours unsuccessfully.

Do you know how could I get it?

Thanks in advance,

Pat

Pat,
You will have to add a set_notification_body() function in KReport Class.
Look at modules/Opportunities/Opportunity.php -> set_notification_body() and get inspired.

Val

Hi Val,

Thanks for your reply. I already added it, but the email received is the default and I need to send a custom one. I suspect that the problem is in the label I use in the HTML template, which has the following structure:

A report has been assigned to you

{ASSIGNER} has assigned a report to {ASSIGNED_USER}.
You may review this report at:
<{URL}>

I have tried a lot ot labels (KReports, Kreports, KREPORTS, KReport, Kreport, KREPORT, …) but no one has worked.

Any idea on how to get it?

Thanks in advance,

Pat

Pat,

you created a custom notify template (custom/include/language/en_us.notify_template.html) or modified the core template by adding

<!-- BEGIN: KReport_Subject -->
SpiceCRM KReport - {KREPORT_NAME}
<!-- END: KReport_Subject -->
<!-- BEGIN: KReport -->
{ASSIGNER} has assigned a Report to {ASSIGNED_USER}.

Name: {KREPORT_NAME}

You may review this Report at:
<{URL}>
<!-- END: KReport -->

Then you added following method to KReport class in modules/KReports/KReport.php

function set_notification_body($xtpl, $kreport)
{
    $xtpl->assign("KREPORT_NAME", $kreport->name);
    return $xtpl;
}

and you just get the default mail text?
Do I understand correctly?

Val

Yes Val, that’s what I did and when the report is assigned it always sends the default email template:

Assigned {OBJECT}

{ASSIGNER} has assigned a(n) {OBJECT} to {ASSIGNED_USER}.

You may review this {OBJECT} at:
<{URL}>

Thanks for your help.

Pat

Pat,

it works properly under SpiceCRM.
Which CRM in which version do you have in use?

Val

I’m using Sugar CE 6.5 Val, but I suppose the behaviour should be the same as under Spice. For all the other modules it is working in the same way.

Thanks for your help,

Pat

Pat,

I just implemented the code in a SugarCRM CE 6.5.18, it works.
Do you have multiple languages and may only 1 notify_template which is not the one for the default language set?
What can also do is

  1. debug include/utils.php get_notify_template_file() to see if the right template is retrieved,
  2. re-check where you inserted code parts.
  3. re-check the name of your custom/include/language/en_us.notify_template.html

Val

Hi Val,

I checked:

  • The notify_template (custom/include/language/en_us.notify_template.html). It includes the following code for KReporter in the language used in Sugar (english):
<!-- BEGIN: KReport_Subject -->
SpiceCRM KReport - {KREPORT_NAME}
<!-- END: KReport_Subject -->
<!-- BEGIN: KReport -->
{ASSIGNER} has assigned a Report to {ASSIGNED_USER}.
 
Name: {KREPORT_NAME}

You may review this Report at:
<{URL}>
<!-- END: KReport -->
  • The controller (modules/KReports/controller.php). It has the true parameter in action_save function:

function action_save() {
global $mod_strings;
if (empty($this->bean->name)) {
$this->bean->name = $mod_strings[‘LBL_DEFAULT_NAME’];
}
$this->bean->save(true);
}

  • The KReport class (modules/KReports/KReport.php). It includes the set_notification_body function:

function set_notification_body($xtpl, $kreport){
$xtpl->assign(“KREPORT_NAME”, $kreport->name);
return $xtpl;
}

  • The include/utils.php, debugging it. The right template is retrieved, but instead of taking KReport’s template it takes default’s one:
<!-- BEGIN: Default_Subject -->
[CRM] Assigned {OBJECT}
<!-- END: Default_Subject -->
<!-- BEGIN: Default -->
{ASSIGNER} has assigned a(n) {OBJECT} to {ASSIGNED_USER}.

You may review this {OBJECT} at:
<{URL}>
<!-- END: Default -->

I can’t find what is wrong. My version is Sugar CE 6.5.11 (Build 8754).

Thanks for your help,

Pat

Pat,
I don’t see the BEGIN - END lines in your template modification

<!-- BEGIN: KReport_Subject -->
Report - {KREPORT_NAME}
<!-- END: KReport_Subject -->
<!-- BEGIN: KReport -->
{ASSIGNER} has assigned a Report to {ASSIGNED_USER}.

Name: {KREPORT_NAME}

You may review this Report at:
<{URL}>
<!-- END: KReport -->

Val

Hi Val,

I have modified my last post so that you can see them.

Thanks in advance,

Pat

Pat,

In my code the template part is defined for KReport. The comments have a meaning in an xtemplate. They define the blocks that will be parsed. In your template you define for default, not for KReport.

Val

Yes, Kreport’s block is in the first point of my post, Val.

Thanks!

Pat

Pat,

I installed a sugar ce 6.5.11, loaded KReporter 3.1, customized as described. It works.
Any error in sugarcrm.log?
What is your php version? I used 5.6.
Next debug step is function parse() in XTemplate/xtpl.php

Val

Hi again Val,

There’s no error shown in the log. I use PHP version 5.3.29.

I’m going to debug parse function and will let you know the result.

Thanks for your help.

Pat

Hi Val,

I have debugged function parse(), and what it receives as bname is [Default]. Do you know where parse function is called from?

Thanks in advance,

Pat

Hi Pat,

data/SugarBean.php
function create_notification_email()

Val