Sage CRM 7.2: Controlling the properties of New Buttons adding using the Client Side API

Hints, Tips and Tricks

Technical Hints Tips and Tricks that cover customization and development using Sage CRM. API usage and coding are covered.

Sage CRM 7.2: Controlling the properties of New Buttons adding using the Client Side API

  • Comments 4
  • Likes

The previous article "Calling Extensions (ASP pages and .NET assemblies) from Buttons added using the Client Side API" discussed how new buttons can be added to system screens.

This article will look at how we can add the button exactly where we need and how we can control the behaviour of the button.

You can read about the addButton method in the online documentation.

http://help.sagecrm.com/js-api/classes/crm.html#method_addButton

The basic usage of the method is

crm.addButton (buttonURL, captionfamily, captioncode, [options object] )

The fourth parameter is either a string (as in the example below) or an object that defines the properties to be used in the button definition.

[code language="javascript"]
<script>
crm.ready(function(){
var buttonimage = '..\\Themes/img/color/buttons/mailmerge.gif';
var buttonaction = crm.url(542);
crm.addButton(buttonimage,'Tabnames','document',buttonaction);
})
</script>
[/code]

Note: The code above can be added to the Custom Content box of the CompanyBoxLong screen.

The simple 'string' example above adds the button onto the screen but at the end of the existing panels of button below the 'Help' button. This would normally not be a very desirable thing as the bottom button on the right of the page should be the Help button to ensure a consistent user experience.

Building the Object

Consider this code

[code language="script"]
<script>
crm.ready(function(){
var buttonimage = '..\\Themes/img/color/buttons/search.gif';
var stringURL = 'http://community.sagecrm.com/search/default.aspx#q='+escape(crm('comp_name').value());
var buttonaction = {
'href': '#',
'index': 2,
click:function(){window.open(stringURL, 'newwindow' , 'toolbar=0 , scrollbars=0, location=0, statusbar=0, menubar=0 , resizable=0, width=800, height=400, left = 340, top = 200');}
};
crm.addButton(buttonimage,'LPGadgetNames','Sage CRM Community News_13',buttonaction);
})
</script>
[/code]

The options are passed as an object in JSON with the following parameters

{
'href': '#',
//The hyperlink location
'index': 2,
//This represents the position in the Button group.
click:function(){window.open(stringURL, 'newwindow' , 'toolbar=0 , scrollbars=0, location=0, statusbar=0, menubar=0 , resizable=0, width=800, height=400, left = 340, top = 200');
//The function called
}

Comments
  • HI

    I have sageCRm7.2 and on the company form I add a button  linked to an ASP page that page send some information to a temporary table. Now I want to add a confirmation dialog box. "Are you sure you want to send those informations?" How can I do that.

    Thanks for your help.

  • Hello

    If you consider the standard behaviour in Sage CRM you have the option of making it work like a delete page - which is an intermediate review page rather than a popup.  That is very easy to create.

    Or you can create you own popup dialog.  You can mix Plain Old JavaScript and jQuery with the Sage CRM 7.2 API calls.  

  • Hi Jeff,

    I'm trying to use this example, but nothing happens. I'm alway redirected to the login page.

    The problem only happens if I try to send an object instead of a string in the fourth parameter.

    Any ideas?

    Cheers

    Tiago

  • Are you trying to link back into Sage CRM?  What are you trying to call from the button?