Tags

CRM & Technology Management


Sales and Marketing Advisor


Sign Up For the Newsletter

Login

Welcome to the Technology Advisors Blog!!

Technology Advisors CRM and Technical Information
May 31
2011

Creating OnChange and OnSave events in SugarCRM - Part 2

Posted by: Justin Kuehlthau in MyBlog

Tagged in: SugarCRM

Justin Kuehlthau

In the first post in this series on SugarCRM onload and onchange events I looked at how to add the events to the edit view.  In this post I will look at how to call a function from a JavaScript file.  In my third post, this will allow us to add JavaScript code that is more useful than an alert.

The first step is to tell SugarCRM where our new JavaScript file will be located.  To do this we update the view.edit.php file located at:
..\custom\modules\Cases\views\view.edit.php.

In my case, this file already existed so I just had to add the display() function to the file:
function display() {
   echo '<script src="/custom/include/javascript/updateSubType.js"></script>';
   $this->ev->process();
   parent::display();
}

As this code points out, the next file I need to update is the updateSubType.js file located at:
..\custom\include\javascript\updateSubType.js.
In this case, I created this file from scratch and inserted the updateSubType function which will be called in my editviewdefs.php file we updated in the last post.

For this example, my function has one line in it which is an alert. The function is:
function updateSubTypeFunction() {
  alert("Custom JavaScript Function");
}

The last change we need to make is to call our new function from editviewdefs.php.  This is the file we edited in the last post.  Here is the updated code to call our new JavaScript function.

In the templateMeta array, change the code to:
'javascript' => '<script type="text/javascript"> onload=updateSubTypeFunction(this); </script>',

In the Type field's  displayParams array, change the code to:
'javascript' => 'onchange=updateSubTypeFunction(this);',

This code will cause a popup window to show when you edit a Case and when you change the Case's type. Next post I will put it all together.

Hits: 2000
Comments (0)Add Comment

Write comment
smaller | bigger

security code
Write the displayed characters


busy