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.
So I'm trying to accomplish something like this(https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/21178-refresh-sub-panel-values-when-another-sub-panel-is-updated#75194)
But instead of reloading a whole subpanel through the controller.php I'm trying to find a way to refresh a single field.
Can anyone advise what method needs to be used to reload a field?
For example to reload a subpanel it's
**
showSubPanel('SUBPANEL_NAME',null,true);
**
But what is the JS method that reload a single field?
I couldn't find any built-in functions in suiteCRM that do it, spent a lot of time going through the chrome debugger, but nothing worked.
Here's a video that explains what's happening and the actual code example https://youtu.be/ebuwWZoSYCk
You need to get the new status from the back-end then update the field inside the controller.php with:
document.querySelector('div[type="enum"][field="$field_to_update"]').innerHTML = "$inventory_status_c";
The whole controller.php file example is here, it all makes sense if you watch the 5 minute video:
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;
}
}
}
?>