问题
I need to add a button to one of my detail views. This button should open a pop-up, which loads some data from a service, displays it, etc ( not important at this point).
I have managed to add the button using the vardefs mechanism in Sugar. Then I tried to hook some logic to the button. That's where I got stuck.
I found this advice on how to proceed: https://community.sugarcrm.com/thread/28658-how-can-i-add-custom-button-next-to-save-cancel-on-account-module-and-custom-module#comment-84253
The way the button was added was the same as what has worked for me, so it seemed legit.
The problem is with adding the external script files - jQuery and my custom script file. That part doesn't seem to work. When I load the page and click the button, I get
RefereneError: myButtonFunt is not defined
The paths in the example are relative, (they start with ./), and I tried to extrapolate for where the files are located in my project. I've tried several things, in the end I just put in absolute paths (starting at the root folder of SugarCrm) :
array (
'javascript' => '
<script src="/custom/include/javascript/jquery-1.4.4.min.js" type="text/javascript"></script>
<script src="/custom/modules/Cases/scripts/detailview/additionalInfoPopup.js" type="text/javascript"></script>
',
),
nothing works. I have verified that the files are exactly where the paths are pointing, by navigating to them directly in the browser. I've even tried changing the path to "./somefile.js" and placing the file in the same folder where the detailviewdefs.php file is (I decided to skip the jQuery reference, because when the page is loaded jQuery is present - and it's a newer version than the one I'm trying to includE). Nothing. Function myButtonFunt is undefined. The file I've referenced doesn't seem to be loaded in the browser's dev tool. Looking at the source of the page there is no mention of my js file.
Obviously the example was made for editviewdefs.php, and I'm using it in detailviewdefs.php, but it seems to me like it shouldn't matter. In my detailview.php the templateMeta array starts with
'form' => array (...
I have tried putting my javascript array both in and out of the form array. Neither approach worked.
I have no idea what to do. At this point I would be ok with any approach that would include my js file so that the button can trigger it. Any help would be appreciated.
回答1:
SugarCRM 6.5 is ancient, so I hope I remember this right:
I believe you are supposed to use actual JavaScript in that section, rather than what you are doing (HTML script tags).
So maybe try an approach similar to this (loading external JavaScript by using JavaScript): Using Javascript to load other external Javascripts
来源:https://stackoverflow.com/questions/59142652/adding-a-button-with-custom-javascript-in-sugarcrm-6-5