which version are you using, what is your environment?
he’s referring to the notification mail on user assignment, that’s handled by the notify template, you’re in the correct path but you need to modify the /modules/Cases/Case.php specifically the function set_notification_body($xtpl, $case) you need to add the case_number xtpl there variable, remember to copy this file and modify it in the custom folder
best regards
Mike do you want to create a simple PR adding this into the code? It feels like an obvious thing that would benefit more people.
Thanks
Version 7.9.7
Sugar Version 6.5.25 (Build 344)
Per @mikebeck I added one line to: public function set_notification_body($xtpl, $case)
$xtpl->assign('CASE_NUMBER', $case->case_number);
and can get the value as {CASE_NIUMBER} in the modified subject line
Real easy if you know where to look!
Thank you for your help
Months later, I stumbled upon this again and decided to make a simple PR:
Our SuiteCRM version is 8.6.0. I check the file modules/Cases/Case.php and notice that this line is already in the file:
$xtpl->assign('CASE_NUMBER', $case->case_number);
But why is the case number not shown in our notification email?
Can you look at the Case Assignment email notification template, and see if the variable CASE_NUMBER
is used anywhere in there, like in the Subject (the expected place to show the case number), or in the Description?
I believe you are referring to this file include/language/en_us.notify_template.html
Indeed, the variable CASE_NUMBER
is missing.
<!-- BEGIN: Case_Subject -->
<p>SuiteCRM Case - {CASE_SUBJECT}</p>
<!-- END: Case_Subject -->
<!-- BEGIN: Case -->
<p><b>{ASSIGNER}</b> has assigned a Case to <b>{ASSIGNED_USER}</b>.</p>
<p>
Subject: {CASE_SUBJECT}<br/>
Priority: {CASE_PRIORITY}<br/>
Status: {CASE_STATUS}<br/>
Description: {CASE_DESCRIPTION}
</p>
<p>You may <a href={URL}>review this Case</a>.</p>
<!-- END: Case -->
I added this line Case Number: {CASE_NUMBER}<br/>
<!-- BEGIN: Case_Subject -->
<p>SuiteCRM Case - {CASE_SUBJECT}</p>
<!-- END: Case_Subject -->
<!-- BEGIN: Case -->
<p><b>{ASSIGNER}</b> has assigned a Case to <b>{ASSIGNED_USER}</b>.</p>
<p>
Case Number: {CASE_NUMBER}<br/>
Subject: {CASE_SUBJECT}<br/>
Priority: {CASE_PRIORITY}<br/>
Status: {CASE_STATUS}<br/>
Description: {CASE_DESCRIPTION}
</p>
<p>You may <a href={URL}>review this Case</a>.</p>
<!-- END: Case -->
But in the received notification email, I got this.
I do not think the variables used in the email templates are the same as the variables used in en_us.notify_template.html
. However, I do not know much about coding, so I may be wrong.
What is your intended suggestion?
- Admin → Repair → Quick repair & rebuild
- Check if you have to run some commands on 8.6 to update changes
- Go to Admin->Developer Tools->Studio->Cases->Fields->check case number Name
I have inserted a debug point within the function set_notification_body
to check if there is a value returned for case_number. The result captured in the log shows that case_number value is empty.
I have no idea how to proceed from here.
public function set_notification_body($xtpl, $case)
{
global $app_list_strings;
$xtpl->assign('CASE_NUMBER', $case->case_number);
$xtpl->assign('CASE_SUBJECT', $case->name);
$xtpl->assign(
'CASE_PRIORITY',
(isset($case->priority) ? $app_list_strings['case_priority_dom'][$case->priority] : '')
);
$xtpl->assign('CASE_STATUS', (isset($case->status) ? $app_list_strings['case_status_dom'][$case->status] : ''));
$xtpl->assign('CASE_DESCRIPTION', nl2br($case->description));
// Debug point: Notification body set
debug_log("Notification body set for the case. Case number: " . $case->case_number);
return $xtpl;
}
Is that a newly created case? Maybe the case number has not been assigned (created) yet, so it is not available at that point in the execution.
If you can get a stack trace at that point, you can check the calling functions to see if it’s something that can be fixed.
Hi @pgr , yes, it is a newly created case.
Now, in Case.php, I have inserted debug points into two of the functions with stack trace enabled:
- set_notification_body
- fill_in_additional_detail_fields
Below is the output log captured after sending a new email to the group email account (Create Case from Email
is enalbed).
I notice that for the function call of set_notification_body
. the returned value of case_number is null. But for the function call of fill_in_additional_detail_fields
, the returned value of case_number is 762, which is correct.
[2024-05-28 02:36:12] Notification body set for the case. Case ID: 6fc2db15-7455-2462-ff6c-66554365da51, Case number:
Stack trace:
Array
(
[0] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/Cases/Case.php
[line] => 348
[function] => debug_log
)
[1] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/data/SugarBean.php
[line] => 3490
[function] => set_notification_body
[class] => aCase
[type] => ->
)
[2] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/data/SugarBean.php
[line] => 3387
[function] => create_notification_email
[class] => SugarBean
[type] => ->
)
[3] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/data/SugarBean.php
[line] => 3346
[function] => send_assignment_notifications
[class] => SugarBean
[type] => ->
)
[4] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/data/SugarBean.php
[line] => 2511
[function] => _sendNotifications
[class] => SugarBean
[type] => ->
)
[5] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/InboundEmail/AOPInboundEmail.php
[line] => 112
[function] => save
[class] => SugarBean
[type] => ->
)
[6] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/Schedulers/_AddJobsHere.php
[line] => 669
[function] => handleCreateCase
[class] => AOPInboundEmail
[type] => ->
)
[7] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/SchedulersJobs/SchedulersJob.php
[line] => 529
[function] => pollMonitoredInboxesAOP
)
[8] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/include/SugarQueue/SugarCronJobs.php
[line] => 191
[function] => runJob
[class] => SchedulersJob
[type] => ->
)
[9] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/include/SugarQueue/SugarCronJobs.php
[line] => 233
[function] => executeJob
[class] => SugarCronJobs
[type] => ->
)
[10] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/cron.php
[line] => 100
[function] => runCycle
[class] => SugarCronJobs
[type] => ->
)
)
[2024-05-28 02:36:13] Filled additional details for the case. Case ID: 6fc2db15-7455-2462-ff6c-66554365da51, Case number: 762
Stack trace:
Array
(
[0] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/Cases/Case.php
[line] => 224
[function] => debug_log
)
[1] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/data/SugarBean.php
[line] => 4720
[function] => fill_in_additional_detail_fields
[class] => aCase
[type] => ->
)
[2] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/InboundEmail/AOPInboundEmail.php
[line] => 113
[function] => retrieve
[class] => SugarBean
[type] => ->
)
[3] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/Schedulers/_AddJobsHere.php
[line] => 669
[function] => handleCreateCase
[class] => AOPInboundEmail
[type] => ->
)
[4] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/modules/SchedulersJobs/SchedulersJob.php
[line] => 529
[function] => pollMonitoredInboxesAOP
)
[5] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/include/SugarQueue/SugarCronJobs.php
[line] => 191
[function] => runJob
[class] => SchedulersJob
[type] => ->
)
[6] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/include/SugarQueue/SugarCronJobs.php
[line] => 233
[function] => executeJob
[class] => SugarCronJobs
[type] => ->
)
[7] => Array
(
[file] => /home/mydomain/public_html/suitecrm8m/public/legacy/cron.php
[line] => 100
[function] => runCycle
[class] => SugarCronJobs
[type] => ->
)
)
The problem is exactly that, the notification email is getting populated just before the number is saved in the DB, so someone is suggesting changing that order:
I have tested the fix mentioned in your linked issue: move the line
$this->_sendNotifications($check_notify);
to after the if-else block.
However, it does not work for my case. The returned value for case_number is still null.
This code is complex, and not very well done. I had to fix it for my add-on PowerReplacer.
I just dug up my notes at the time, and you can see for yourself how messy it gets
This is what the Create Case process does currently:
1. Receives an Email in an inbox marked as "auto create case"
2. Creates a Case and copies some details from the Email into it.
3. Looks for Account(s) that match the email sender, sets the Case creator to be the first of those Accounts
4. Side-effect of the above: a case assignment notification email is sent to the user to whom the Account is assigned
5. Links the Email to the new Case
6. Links the new Case to the contact (some extra complexity here, depending on whether the sender email belongs to an account, a contact, both, or even several records of each).
7. Side effect of the above: some change notifications emails are sent
8. Copies all incoming Email attachments as files linked to SuiteCRM Notes records, and links them all to the Case.
9. Saves the Email record filling in some more details
10. Side-effect of above: sends change notifications to user assigned to the email
11. Finally starts working on the Reply Email, gathering details such as the Template to use and "From name" and "From address", and creates a subject line with the Case number
12. Does NOT replace any variables in the template! That code simply is not there.
13. Tries to send, but most email servers will reject it due to a wrong "From address".
So as you see - three emails, each with parts missing… the one you’re seeing seems closer to what is intended, but struggles with the new case number. The one that had a better chance of being complete (the last one) is quite a mess to repair
Creating the new case number in step 2 shouldn’t cause any issue, and would fix the bugs where case number does not exist yet - causing notification emails with no case numbers!
- Receives an Email in an inbox marked as “auto create case”
- Creates a Case and copies some details from the Email into it.
- Looks for Account(s) that match the email sender, sets the Case creator to be the first of those Accounts
- Side-effect of the above: a case assignment notification email is sent to the user to whom the Account is assigned
…
I don’t recall exactly (and can’t test right now) but I think the number is created, the problem is that the way one code calls the other, hooks, etc, at some point we’re not using the same bean we were using originally, but the one in the database gets referenced, and it is incomplete at that point (in the middle of the save).