Controlling the properties of New Buttons adding using the Client Side API

1 minute read time.

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.

crm.ready(function(){
var buttonimage = '..\\Themes/img/color/buttons/mailmerge.gif';
var buttonaction = crm.url(542);
crm.addButton(buttonimage,'Tabnames','document',buttonaction);
})

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

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);
})

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
}

Parents
  • 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.

Comment
  • 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.

Children
No Data