Send notification not working

Email notification is not sending while creating a case at the first timet to assignee. But when we update case and reassign case to other User then it works.
I found the issue at following line

whereas it should be below if else block because at that time case is not created. It gets only created in the else block having insert() function.
When I moved _sendNotification() line below if else block then it’s working as intended.

Your thoughts? Am I doing correct changes.

Looks good. Please create a new Issue on github with a link back to this post, and then a Pull Request with the edited file, and referring to your Issue number, so that your fix can be reviewed tested and if approved, added into the app.

I wouldn’t change that on SugarBean::save() , it’s too vast a change, everything goes through that, and depending on the logic hooks that are defined, it will do different things in practice.

I would look for a solution in the hooks that are defined for Cases handling, I think that’s where the bug is. Remember that AOP Cases is historically a SalesAgility add-on to SugarCRM. Check the hooks on the directory modules/AOP_Case_Updates/

What exactly I need to check here?
I don’t see any changes related to sending an email when new case is created.
Can you share file and function that will be possible cause of the issue?

You have these definitions of hooks in the installer, for Cases module:

SuiteCRM/install/suite_install/AdvancedOpenPortal.php at 873557561b8fbed15d586a0d9217037a0b96820c · salesagility/SuiteCRM · GitHub

You’ll find them in custom/modules/Cases/logic_hooks.php on your installed system.

I think the important ones are the ones calling saveUpdate, which eventually call the bean save.

You can try setting a break-point at the bean save and checking the call stack to see where it’s being called from. If you can manage a fix higher up the call stack, then it would fix only this specific case, without changing hundreds of code flows in SuiteCRM (in a way that will be impossible for you to test, since they might be custom flows, specific to some installations, but not all).

I don’t see any way using which we can fix on that logic hooks OR before that because eventually at that point of time Case is not created. It gets created only in that if else block and inside _sendNotification() function, we’ve one query to fetch contact name and case number based on case id. So placing _sendNotification below that if else block makes sense to me.
I debugged using Xdebugger and sensed that it is only solution unless you can show me the exact issue where I can make changes.

When you set the break-point, which function is calling that SugarBean::save? Where is it being called from?

Regarding the _sendNotifications not sending the email when the Case is not created yet, why exactly is that? I understand that the database does not have the record saved yet, but the Case object is there in $this, why is that not enough to get the email through? How is it dependent on the DB? Maybe if you step through that code maybe you can see what is missing. Please also check what is the value of $check_notify when the function is called.

I am just trying to understand what is going on a little better.

Oh, ok. I think now I understood the confusion.
Email is sending to new assignee without Contact name and Case Number. No issues with email sending functionality.
Only issue is that it is not able to get Contact name and Case Number because by that time case is inserted into database as query that fetches these information with where condition containing case_id is not yet inserted into Cases table. It’s still in the $bean.