Posted by: Miracle Studios | October 8, 2008

Sugarcrm Tutorial : How to use ajax with SugarCRM

Hello people, I always ask my self how to embed ajax within sugar, it is to look at an EditView of a contact and to do some action without refreshing the browser. Well, after a little study, I could do it, so I will share it with you how to add ajax in sugar.
I will explain how to add to an EditView a buttom that when we click on it, it executes a php application and bring its content. The invocation to that php file will be using YUI (yahoo user interface). The idea is, when we press the button, it will call an external php that will execute its code and it will get a param from sugar.
First at all, we have to install an exelent module developed by patrizio gelosi named EnhancedStudio, This module adds a new type of field named ‘Code’ field, that will help us to add php code and a lot of things more.
After install this module, we have to add the code field to the editview of contacts module, to do this we have to:
1- Go to Admin->Studio->Contacts->Fields. We have to add a new ‘Code’ field name ‘yui_test’
2- We have to add the following code:
PHP Code:
echo ‘
first_name . ‘”, callback);
// –>

this will change…

3- After add this content, we must save changes and add this field to the editview of contacts. To do this, we have to go to Contacts->Layout->EditView, search for our new field named “yui_test” and drag it to the template.
4- Finally, we must create the file to be invoked. To do this we must create “my_app.php” within sugarcrm root directory. The content is the following:
PHP Code:
echo “

The contact name is: ” . $_REQUEST[‘name’] . “

for ($i=0; $i < 5; $i++) {
echo “Hello world! $i
echo ‘

width=”400″ height=”500″ scrolling=”auto” frameborder=”1″ transparency> </p> <p>Alternative text for iframe.</p> <p>
5- Ready! It’s done. We were a little more ambitious, because we passed the name of the contact by GET to our application, our app will show the name of the contact, also will print five ‘hello world’ and finally we will show wikipedia within the contact detail.
With all of this, I wanted to show the potential and ease at time to add code in sugar
If you have any problem with the code, let me know and I’ll try to help you.

Posted by:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s


%d bloggers like this: