To create a custom button on the detail view of a module {MODULE_NAME} use the below code
Create a file or modify the below file custom/modules/{MODULE_NAME}/views/view.detail.php
<?php if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point'); require_once('include/json_config.php'); require_once('include/MVC/View/views/view.detail.php'); require_once('custom/include/general_functions.php'); class {MODULE_NAME}ViewDetail extends ViewDetail { function {MODULE_NAME}ViewDetail() { parent::ViewDetail(); } function display() { $this->dv->defs['templateMeta']['form']['buttons'][101] = array ( 'customCode' => '<input title="Custom Text Here" accesskey="{$APP.LBL_PRINT_PDF_BUTTON_KEY}" class="button" onClick="javascript:CustomFunctionHere();" name="tckpdf" value="Custom Text Here" type="button">'); parent::display(); } } ?>
Related articles
- How to know if a Contact from SugarCRM is opt out from emails using REST API? (stackoverflow.com)
- Thoughts on Sugar CRM (ebiztechs.wordpress.com)
- Sugar CRM continued.. (ebiztechs.wordpress.com)
I modify in custom/module/Leads/views/view.detail.php
My code :
$GLOBALS[‘listbutton’] = $this->dv->defs[‘templateMeta’][‘form’][‘buttons’]; if ($this->bean->status == ‘Converted’) {
unset($this->dv->defs[‘templateMeta’][‘form’][‘buttons’][0]);
}
parent::display();
$GLOBALS[‘log’]->debug(“INFOdation log Display”);
$this->dv->defs[‘templateMeta’][‘form’][‘buttons’] = $GLOBALS[‘listbutton’];
But when status ==’New’ , the edit button still hide. Could you help me. I only want edit button hide when status == ‘Converted’, other status it has to apperance.
LikeLike
This works, but you need to have developer mode turned on. Otherwise it will only work on the first load. The SugarCRM Dev blog has a nice post on how to do add buttons to the detailviewdefs.php that show/hide based on conditions: http://developers.sugarcrm.com/wordpress/2012/11/29/using-role-controls-on-detailview-and-editview-custom-buttons/
LikeLike
Wow………… the big boys are on this blog!!!!
LikeLike
[…] SugarCRM: Create button on the detail view « Php Bugs – Create a file or modify the below modules. How to know if a Contact from SugarCRM is opt out from emails using REST API? (stackoverflow. Posted on February 7, 2012, in SugarCRM and tagged Customer relationship management, PHP, SugarCRM. […]
LikeLike
Hy thx , it was very usefull.
can u please tell me how i can embedded javascript code in this view.detail.php?
because i want to dynamically hide and display panel. Thx
Stev
LikeLike
Hello Stev,
You can use the function preDisplay in view.detail.php to include the JavaScript file. Please refer this URL http://wp.me/p8AtY-cP
Thanks and Regards
PHPBugs
LikeLike
Really useful. Before this I was trying to do it through the metadata because that’s where I saw the other buttons defined but this is much cleaner. Now I just have to tie this to an event handler and all will be good. Thanks!
LikeLike
I precisely had to thank you so much once again. I am not sure the things that I could possibly have accomplished without the tips discussed by you over my question. It was the difficult scenario for me, but taking note of a new professional way you processed the issue forced me to leap for happiness. Extremely happier for this work and in addition wish you comprehend what a great job you’re getting into instructing others thru your blog post. Most probably you’ve never got to know any of us.
LikeLike