Adding Buttons to an ASP Page

Hints, Tips and Tricks

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

Adding Buttons to an ASP Page

  • Comments 2
  • Likes
Consider the code below. This is for a simple edit screen for the Opportunity entity.

var intRecordId = CRM.GetContextInfo("opportunity","oppo_opportunityid");
var myBlock = CRM.GetBlock("opportunitydetailbox");
var myRecord = CRM.FindRecord("opportunity","oppo_opportunityid="+intRecordId);

We can control buttons on this screen using 2 mechanisms. First we can control which 'system' buttons are used. Secondly we can add our own custom buttons.

Controlling System Buttons

These are the Change/Save button, the Delete button and the Continue button. The DisplayButton() method accepts either "1", "2", or "4" as a parameter. Note, variables called Button_Default, Button_Delete and Button_Continue are set in the ASP page's standard include file..

//Button_Default, Button_Delete, and Button_Continue are variables set in the include file
DisplayButton(Button_Default) = true;
DisplayButton(Button_Delete) = true;
DisplayButton(Button_Continue) = true;

The Default Button of the form is the Change/Save button. You can provide a new graphic for this using the ButtonImage property. You can dynamically change the default button's caption using the ButtonTitle property.

If you are setting the ButtonTitle property to make sure that translations work then there should be an existing button caption record in the translation (custom_captions) table.

Any new image referenced should be in the img\buttons\ folder.


ButtonTitle = "Click me";
ButtonImage = "mygif.gif";

Or to have the button title and image change when only in Edit mode

ButtonTitle = "Promote";
ButtonImage = "promote.gif";

The buttons by default appear on the top, right of the screen. but we can use the ButtonLocation and ButtonAlignment properties to change the position to where we want it to be.

Note: The variables Bottom, Left, Right, Top are set in the ASP include file, e.g. eWare.js or accpaccrmnolang.js

ButtonLocation = Bottom;
ButtonAlignment = Left;

Adding Custom Buttons

The basic way we can call a button is

var strCallASPButton = CRM.Button("ASP","save.gif", CRM.Url("myPage.asp"));

The CRM.URL() method will build the button URL with the correct path, context and session variables. The Button() method builds the button. It can accept either 3, 5 or 6 parameters.

There are lots of different ways of using the Button method.

We can use the method to call an inbuilt CRM action e.g 130 is find company

var strFindCompanyButton = CRM.Button("search","search.gif", CRM.Url(130));

Calling an ASP page is easy

var strCallASPButton = CRM.Button("ASP","save.gif", CRM.Url("myPage.asp"));

We don't have to use the eWare.URL method. We see that the button URL can be manually built

var strCallCustomURL = CRM.Button("Dummy","cancel.gif","/crm/eware.dll/do?act=185&key0=4&key4=1&Mode=1&CLk=T&SID="+Request.QueryString("SID"));

The 4th and 5th parameter are used to control access to the button using the user's security rights. For example to build a button that is only available for users with insert rights on company entity we can write:

var strNewCompanySecurityButton = CRM.Button("New","newcompany.gif", CRM.Url(1200),"COMPANY","INSERT");

There are times when we will want to call an action but will need to add extra information into the URL, for example

var strCallMyCalendar = CRM.Button("Calendar","calendar.gif", CRM.Url(183)+"&HIDDENLISTMODE=2");

We can use the button to call clientside behaviour and pseudo URLs like mailto: or javascript:

var strSearchFormClearButton = CRM.Button("Clear", "clear.gif", "javascript:document.EntryForm.em.value='6';document.EntryForm.submit();");

We can even have our button pop open another window. The sixth parameter will be the new windows name.

var strCustomHelpButton =CRM.Button("Test", "test.gif", CRM.URL("Test.asp"), "", "","test_target");
  • Are you able to make a button that Saves and redirects? For example, an Opportunity custom ASP page on workflow that saves the screen and then redirects back to the Opportunity Summary - CRM.URL(260).

  • The 'post-save' redirect would have to be in the ASP page.  There are examples on the blogs.