How to ask 'Are you sure?' alert

Hello everybody,
i’m here again asking you (i hope) a simple thing.
When i save an aos_quotes (related to an account record), if a field in accounts_cstm.field is null or != ‘’, i want to generate an alert box that says ‘Are you sure?’.
Is there a way upgrade safe?
Thankyou again! :cheer:

Something like this?

https://gunnicom.wordpress.com/2015/09/21/suitecrm-sugarcrm-6-5-add-custom-javascript-field-validation/

1 Like

That could Be a great solution :cheer:
But in your opinione how can i insert a field from a related module in the if condition script?

You can do anything, but since you’re in the front-end, to avoid making things too complicated it would be helpful if you had that data already available there.

Sometimes a workaround is better, like adding a custom field to this record, and populating it in a Workflow every time the related record is updated. This way you have the information from the related record always nearby, in the current record.

1 Like

Ok pgr, thankyou for your advice.
I’ve created a beforesave logichook that print the accounts field in the quote.
So now i’ve that value in this module; but how can i show the alert ‘The field ERP NOTE is not empty, are you sure you want to save?’
How can i menage the correct sequence of actions?
Thank you, you’re kind :cheer:

Have you tried the Javascript in the example at that blog I linked? It seems to be adding an error message, see how it is displayed, it’s probably similar to what you need…

Ok, i give you an update.
I’ve created a logichook before_save that brings the field from the Account module to the AOS_quotes module.
Then i’ve created another logichook after_save that shows the alert only if that field is not empty (EDIT: the alert i need is not an ‘Are you sure?’ alert. It is just an ‘Ok’ alert).

The function of the first logichook works well.

The function of second logichook works not totally:
it works only when i make an In Line Edit; when i click on Actions -> Edit -> Save , none of alert is displayed.
I show you all the file i made:

Logichook


<?php
$hook_version = 1;
$hook_array = Array();
$hook_array['after_ui_frame'] = Array();
$hook_array['before_save'] = Array();
$hook_array['before_save'][] = Array(1, 'beforeSaveAOS_Quotes', 'custom/modules/AOS_Products_Quotes/ContrattiAssistenzaAcquistati.php', 'ContrattiAssistenzaAcquistati', 'beforeSaveAOS_Quotes');
$hook_array['before_save'][] = Array(2, 'beforeSaveNazioneUtente', 'custom/modules/AOS_Quotes/NazioneUtente.php', 'NazioneUtente', 'beforeSaveNazioneUtente');
$hook_array['before_save'][] = Array(3, 'beforeSaveBloccoAlyante', 'custom/modules/AOS_Quotes/BloccoAlyante.php', 'BloccoAlyante', 'beforeSaveBloccoAlyante');

$hook_array['after_save'] = Array();
$hook_array['after_save'][] = Array(1, 'afterSave', 'custom/modules/AOS_Quotes/Opportunities_AOS_Quotes_1.php','Opportunities_AOS_Quotes_1', 'afterSave');
$hook_array['after_save'][] = Array(2, 'afterSaveBloccoAlyante', 'custom/modules/AOS_Quotes/Alert.php','AlertAlyante', 'afterSaveBloccoAlyante');
?>

Before_save


<?php
if (! defined('sugarEntry') || ! sugarEntry)
	die('Not A Valid Entry Point');

class BloccoAlyante {

	function beforeSaveBloccoAlyante(&$bean, $event, $arguments) {
		if (! empty($bean->billing_account_id)) {
			$beanAzienda = BeanFactory::getBean('Accounts', $bean->billing_account_id);
			if (! empty($beanAzienda))
				$bean->blocco_alyante_c = $beanAzienda->blocco_alyante_c;
			}
	}
}
?>

After_save


<?php
if (! defined('sugarEntry') || ! sugarEntry)
	die('Not A Valid Entry Point');

class AlertAlyante {

	function afterSaveBloccoAlyante(&$bean, $event, $arguments) {
		if (! empty($bean->blocco_alyante_c)) {
            $blocco_alyante = $bean->blocco_alyante_c;
		    $message = "Attenzione, questo cliente ha un Blocco Alyante: $blocco_alyante";
            echo "<script type='text/javascript'>alert('$message');</script>";
            }
		}
	}
?>

UPDATE: I found a different solution using SugarApplication::appendErrorMessage($message) instead of window.alert($message).