I have a logic hook that changes a field’s value, but in order to see the change I need to refresh the whole page… I want it to refresh the field in real time.
Yep, it’s a good idea, I’m just concerned if it will be upgrade safe in case the markup ever changes in the future and it’s not the same setup (unlikely but still)
Figured out how to do it from the controller.php when a new subpanel item is added.
Here’s the whole controller.php and the 5 minute video that explains what’s actually happening:
class un_inventoryController extends SugarController {
/**
*
*/
function action_SubPanelViewer() {
require_once 'include/SubPanel/SubPanelViewer.php';
// only if this is creation of new sale under accounts, refresh the screen so the salerow subpanel will be refreshed too
if ( array_key_exists('module', $_REQUEST) && array_key_exists('subpanel', $_REQUEST) && array_key_exists('action', $_REQUEST) &&
$_REQUEST['module'] == 'un_inventory' && $_REQUEST['subpanel'] == "un_inventory_leads_1" && $_REQUEST['action'] == "SubPanelViewer") {
write_to_log(array("request" => $_REQUEST), "all conditions filled, custom controller called", true);
// Get the ID of the inventory unit so we can fetch the new status_c field and update the field right away (otherwise we'll have to refresh the page
$inventory = BeanFactory::getBean($_REQUEST["module"], $_REQUEST["record"]);
$inventory_status_c = ucwords(str_replace("_", " ", $inventory->status_c));
$field_to_update = "status_c";
$js=<<<EOQ
<script>
// Update the status
$( document ).ready(function() {
document.querySelector('div[type="enum"][field="$field_to_update"]').innerHTML = "$inventory_status_c";
});
</script>
EOQ;
echo $js;
}
}
}
?>
Great video, once again! The only part I don’t like is the title mentioning that old thing called “SugarCRM”
Since you’re doing these videos, I notice you probably don’t have XDEBUG set up and connected to your PHP Storm? If you don’t, you really should. Sometimes it’s a pain to set up, especially for remote debugging, but it’s really worth the trouble, it’s a game changer for development.