Subpanel: open createview after condition check

I have 2 custom modules, in the first there is a subpanel, for the second module and I would like that if a user click on create button, before to redirect user on createview, check if in the first module a field is set with a particular value. If the check failed, show an alert and don’t open the create form.
Is this possible? Is there a upgrade safe solution?
Thank you so much


It sounds like something that should be doable!

A suggestion might be to extend the subpanel functionality, and add a Custom button to the Subpanel?

This’ll allow you to have a button on the subpanel that performs your custom code, (in this case, Check for a value, then do/don’t redirect)

I’ve found a few short guides around this, hopefully they’ll be a good place to start:

Unless any other user can think of another solution?

Let us know if you’ve got any questions or issues!

thank you so much John.
I think a custom button can be a solution.
In the next days, I’ll try and than I tell you.



Great, Looking forward to hearing how it goes!

Hopefully it meets your needs!

1 Like

Hello, I try to follow the solutions in the links, but I don’t understand, how can I create the same standard “create button”. I don’t want create different button that made something, I would like prevent to go to create a record for child module, if the record of host module, has a field with a particular value.


I haven’t done it myself, but the methods I’d linked above should allow you to achieve your goal.
You will be able to create a custom “Create” button on the Subpanel that can execute your custom code.

You don’t have to follow the tutorials step by step, but they should show you roughly which files/content would need to be edited to achieve this.

(ie: Particularly, the first video linked above shows that a custom layoutdef in:
/custom/Extension/modules/(module name)/Ext/Layoutdefs/filename.php
would allow you to specify a custom Action on the Subpanel, pointing to custom code.

This code can then be noted in a custom widget in:

However, if you don’t wish to create a Custom Create Button, I’m not too sure what methods could be used :confused:
Perhaps some other users have an idea of what steps to take?


The easiest solution is to extend the controller of your second module.

Here is an example of what we do to prevent the creation of quote from a won or lost opportunity:

    public function action_editview()
        if (isset($_REQUEST['opportunity_id'])) {
        	$opportunity=BeanFactory::getBean('Opportunities', $_REQUEST['opportunity_id']);

        	if ($opportunity->sales_stage =='Closed Won' || $opportunity->sales_stage =='Closed Lost'){
	        	SugarApplication::appendErrorMessage('Quotes cannot be created in that stage');
	        	// redirect to detail view so that the error message is displayed
                $url ="index.php?module=Opportunities&action=DetailView&record=".$_REQUEST['opportunity_id'];
1 Like