Hello,
Please help me solution to display popup alert by logic hooks
This logic hooks after save of Case, when Case set to Closed but Task in subpanel is not Completed, the logic hooks will popup alert and restrict save.
Thanks
Hello,
Please help me solution to display popup alert by logic hooks
This logic hooks after save of Case, when Case set to Closed but Task in subpanel is not Completed, the logic hooks will popup alert and restrict save.
Thanks
Hi,
You can use throw exception and popup the alert.Using exception you can restrict the save. Put below code in your logic hooks and check.
throw new SugarApiExceptionNotAuthorized('SUGAR_API_EXCEPTION_RECORD_NOT_AUTHORIZED',array('view'));
throw new SugarApiExceptionInvalidParameter(string_format(
$GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'],
array($extension)
));
throw new SugarApiExceptionError('Unable to load field definition');
Another way is use the Validations of sugarcrm. Please check one of sugarcrm link http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_7.6/UI_Model/Views/Examples/Adding_Field…
Let me know if you need more help.
-BPATEL
Hi Bhavesh Patel,
Thank you very much, I'll try and feedback
Regards
Note that you won't be able to do it in an after_save logic hook as the Case bean would already be updated with the new values.
Additionally, if the above doesn't work, try using sugar_die("your message here")
Thank you very much, I'll try with before_save
Hi Bhavesh Patel
This is my logic hooks
<?php
class CheckClosed
{
public function CheckTask(SugarBean $bean, $event, $args)
{
global $sugar_config, $db,$current_user;
//check Task status
$id = $bean->id;
$query = "SELECT status FROM tasks WHERE parent_id = '$id' AND deleted = '0'";
$result = $db->query($query,true);
$rows = $db->fetchByAssoc($result);
$check = 0;
foreach ($row as $rows) {
if ($row['status'] != 'Completed') {
$check = 1;
$GLOBALS['log']->test('check: '.$id);
break;
}
}
if ($check = 1) {
throw new SugarApiExceptionError('Unable to Closed. Please set Task to Completed');
$GLOBALS['log']->test('check: '.$check);
}
}
}
It dose not work with your code throw new SugarApiExceptionError('Unable to Closed. Please set Task to Completed');
Please help me. Thanks
1) Are you sure the logic hook is firing at all? Have you added this function to the logic hooks array and done a repair and rebuild? Alternatively, you could put this at the top of the function to check it's firing:
$GLOBALS['log']->test('Logic hook is active');
2) You've got an assignment in your code where you should have a comparison operator. Instead of:
if ($check = 1) {
You should have:
if ($check == 1) {
3) Instead of using throw new SugarApiExceptionError, have you tried sugar_die as I recommended:
sugar_die('Unable to Closed. Please set Task to Completed.');
Thank for your reply
1. I'm sure my logic hook is firing at alls
2. New my code, but it did not work
3. Please help me how to display code format in my post
<?php
class CheckClosed
{
public function CheckTask(SugarBean $bean, $event, $args)
{
global $sugar_config, $db,$current_user;
//check Task status
$id = $bean->id;
$status = $bean->status;
$query = "SELECT status FROM tasks WHERE parent_id = '$id' AND deleted = '0'";
$result = $db->query($query,true);
$rows = $db->fetchByAssoc($result);
$check = 0;
foreach ($row as $rows) {
if ($row['status'] != 'Completed') {
$check = 1;
break;
}
}
if ($check == 1 && $status = 'Closed') {
//throw new SugarApiExceptionError('Unable to Closed. Please set Task to Completed');
sugar_die('Unable to Closed. Please set Task to Completed.');
//$GLOBALS['log']->test('check: '.$check);
}
}
}
Well, let's try and break it down bit by bit. Change your code to:
<?php
class CheckClosed
{
public function CheckTask($bean, $event, $args){
sugar_die('Unable to Closed. Please set Task to Completed.');
}
}
This should stop a task from ever being saved. If that doesn't work, then the logic hook isn't firing. If it does work, then log the results of your SQL and figure out why that isn't doing what you're doing. Break the problem into little bits.
With regards to the syntax highlighting - click on 'More ' in the editor, and then click on 'Syntax Highligher'.
Let me know where/if you get stuck.
Thank for your help.
My purpose is stop Case save when set Case to Closed if Task of Case is not Completed and popup Alert.
With your code I did not know how to check Task Completed when Case set to Closed
Hello Bao Tran Hoang,
Please Put below code in your file.
<?php
class CheckClosed
{
public function CheckTask($bean, $event, $args){
throw new SugarApiExceptionInvalidParameter(string_format(
$GLOBALS['app_strings']['LBL_UPLOAD_IMAGE_FILE_NOT_SUPPORTED'],
array($extension)
));
}
}
I have checked this is working fine for me.
Hope it will help you.
-BPATEL