Last active
April 20, 2023 16:27
-
-
Save aserrazina/6124500cc87c3c3bcd5865310f5979d8 to your computer and use it in GitHub Desktop.
Inherit team set from parent note when adding attachments to existing notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//path custom/modules/Tasks/copy_teams.php | |
if (!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); | |
class after_save_copy_notes_class | |
{ | |
function after_save_copy_notes_method($bean, $event, $arguments) | |
{ | |
//Validating that it is a new Note | |
if(empty($bean->fetched_row['id'])) | |
{ | |
//Validating that it is an attachment note and has a parent to copy from | |
if ($bean->attachment_flag == 1 && isset($bean->note_parent_id)) | |
{ | |
//Create a TeamSet bean | |
require_once 'modules/Teams/TeamSet.php'; | |
$ParentTeamSetBean = new TeamSet(); | |
// Load the teams from the parent note | |
$parentNoteBean = BeanFactory::retrieveBean('Notes', $bean->note_parent_id); | |
$teams = $ParentTeamSetBean->getTeams($parentNoteBean ->team_set_id); | |
$NoteBean = BeanFactory::retrieveBean('Notes', $bean->id); | |
$NoteBean->load_relationship('teams'); | |
//Replace the teams on the created note | |
$NoteBean->teams->replace($teams); | |
$NoteBean->save(); | |
} | |
} | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//path custom/Extension/modules/Notes/Ext/LogicHooks/copy_teams_parent_note.php | |
$hook_array['after_save'][] = Array( | |
//Processing index. For sorting the array. | |
1, | |
//Label. A string value to identify the hook. | |
'Copy Teams to attachment Note', | |
//The PHP file where your class is located. | |
'custom/modules/Notes/copy_teams.php', | |
//The class the method is in. | |
'after_save_copy_notes_class', | |
//The method to call. | |
'after_save_copy_notes_method' | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment