Staff
Ilija Studen
on Jul 23. 2008. 1:09 pm
Oh, in that case try this:
if(instance_of($object, 'Project')) {
$docket_id = '12345';
$object->setName($object->getName() . " - [" . $docket_id . "]");
} elseif(instance_of($object, 'Ticket')) {
// ...
}
activeCollab team member |
LinkedIn
nickw
on Jul 23. 2008. 5:27 pm
Still no go.
Doesn't give any errors, it just creates the project with the original name.
Staff
Ilija Studen
on Jul 23. 2008. 11:46 pm
It this the new or existing handler file? Do you have it registered in handlers.php of that specific module?
activeCollab team member |
LinkedIn
nickw
on Jul 24. 2008. 10:12 am
Existing. I elected to add my code to yours, and document my changes.
It's in on_before_object_insert.php
Sorry this is turning into a pain...
Staff
Ilija Studen
on Jul 24. 2008. 10:27 am
Just tested - code is working. Here is how entire handler looks like:
function system_handle_on_before_object_insert($object) {
if(instance_of($object, 'Project')) {
$object->setName($object->getName() . ' [#123]');
}
if($object->fieldExists('created_on')) {
if(!isset($object->values['created_on'])) {
$object->setCreatedOn(new DateTimeValue());
} // if
} // if
$user =& get_logged_user();
if(!instance_of($user, 'User')) {
return;
} // if
if($object->fieldExists('created_by_id') && !isset($object->values['created_by_id'])) {
$object->setCreatedById($user->getId());
} // if
if($object->fieldExists('created_by_name') && !isset($object->values['created_by_name'])) {
$object->setCreatedByName($user->getDisplayName());
} // if
if($object->fieldExists('created_by_email') && !isset($object->values['created_by_email'])) {
$object->setCreatedByEmail($user->getEmail());
} // if
} // system_handle_on_before_object_insert
I've attached a screenshot with a project overview page. You can see that project name is properly altered before save.
activeCollab team member |
LinkedIn
nickw
on Jul 24. 2008. 2:36 pm
Okay its workin' now! Thanks.
I see what the problem was now.
I was instering the code at the end of the file (also tried begining), and I needed to insert it in after:
function system_handle_on_before_object_insert($object) {
Thanks again.
Nick.