Background: I have virtually no prior programming experience, so please excuse any blatant errors and assumptions I may make. That said, I've decided to try to add a wee bit of basic functionality to our case module via a custom logic hook. Hopefully it can benefit everyone out there. Hopefully I don't annoy the sugar gods.
Our company relies heavily on Cases. Currently Sugar only tracks when a case is opened and/or modified. For reporting and billing reasons I need to know when a case is closed... I read the wonderful logic_hooks presentation and decided to add a custom field to track case closures (date_closed_c). I hope to use a logic hook to assign a value to date_closed_c whenever a case is closed.
Problems:
1) Custom field. I added a custom field (date_closed_c) to the cases module. For some reason the studio only lets you select from a small list of data types. I'd like a DateTime but only 'Date' is an option. I changed the field to my liking in phpMYAdmin. Bad? I know not to 'repair custom fields' in the studio if I make such a change.
I'd also like date_closed_c to be null until I close a case (and give it a value). When I edit a case it seems to initialize all my custom fields to '0' even if they are not displayed on the edit screen. hurm. I can live with 00-00-0000 00:00:00.
2)When to apply my logic? I crafted a crude conditional statement to write date_closed_c only when
-before save
-case is closed
-case_closed_c does not exist/is null/is 0?<-- really depends on how i approach problem 1 above.
3) How the heck do I assign the current DateTime to date_closed_c? TimeDate.php really scared me. I read over alot of code and decided to avoid it all and stick with date("Y-m-d H:i:s"). It works. sortof.
So here's what I have now (yes, it's embarrassingly simple)
PHP Code:<?php
require_once('data/SugarBean.php');
require_once('modules/Cases/Case.php');
class CaseSetDateClosed {
function CaseSetDateClosed(&$bean, $event, $arguments)
{
// only set the closed date if the case is closed and there was no previous close date. A case can only be closed once.
if ($event == 'before_save' && $bean->status == 'Closed' && is_null($bean->date_closed_c) )
{
$bean->date_closed_c = date("Y-m-d H:i:s");
}
}
}
?>


LinkBack URL
About LinkBacks



Reply With Quote



Bookmarks