Best practice to send data to an external site and displaying the return in sugar as an alert

Hi all,

I have a custom module of printers, when certain fields are updated in the record I want to send that record data to an external laravel site to update its database.

I currently use logic hooks to do this

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(
1,
'Update Serial Cache',
'custom/modules/S_SerialNumber/update_serial_cache.php',
'update_serial_cache',
'update_to_cache',
);
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(
1,
'Update Serial Cache',
'custom/modules/S_SerialNumber/update_serial_cache.php',
'update_serial_cache',
'get_record',
);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

 the update_to_cache function checks if the fields I want to check have changed and if they have pushes that data to our laravel site over curl to a custom endpoint. The problem is Id like to inform the user with an alert box that the cache was updated or display the error returned from laravel

is it possible to do this in sidecar and have a custome script  running an ajax reguest to the laravel server then using the alerts  to display the return?

I cant use the built in web_logic_hooks as I only want this to happen if certain fields are updated. 

this is my logic hooks custom class

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
class update_serial_cache
{
public function get_record($bean, $event, $arguments)
{
$bean->stored_fetched_row_c = $bean->fetched_row;
// sugar_die('just a test sugar_die.');
}
public function update_to_cache($bean, $event, $arguments)
{
if (!$bean->cached_c) {
$GLOBALS['log']->warn('Not cached: exiting');
return false;
}
$update = false;
if (isset($bean->stored_fetched_row_c)) {
$GLOBALS['log']->warn('OLD: '.json_encode($bean->stored_fetched_row_c));
// Warranty change
if ($bean->stored_fetched_row_c['warrantystart_c'] != $bean->warrantystart_c) {
$GLOBALS['log']->warn('New: '.$bean->warrantystart_c);
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

i used the log  just to check the hook was firing

Parents Reply Children
No Data