Creating an ASP page
Sage CRM ASP pages use the properties and methods of the CRM object to connect to the system database and produce formatted output to the web browser. Standard ASP scripting conventions are observed.
The following example code creates a custom ASP page which enables users to search for contacts in the Sage CRM database and view a list of search results:
<!-- #include file ="sagecrm.js"-->
<%
// Get an empty container block.
var SearchContainer = CRM.GetBlock('Container');
// Add the Person Search Box.
var SearchBlock = CRM.GetBlock('PersonSearchBox');
SearchContainer.AddBlock(SearchBlock);
// Change the label and image on the default button.
SearchContainer.ButtonTitle='Search';
SearchContainer.ButtonImage='Search.Gif';
// If button has been pressed then add the list block to show search results.
if (CRM.Mode == 2)
{
var resultsBlock = CRM.GetBlock('PersonGrid');
resultsBlock.ArgObj = SearchBlock;
SearchContainer.AddBlock(resultsBlock);
}
if (!Defined(Request.Form))
{
// First time - display mode.
CRM.Mode = Edit;
}
else
{
// Mode is always Save.
CRM.Mode = Save;
}
CRM.AddContent(SearchContainer.Execute());
var sHTML = CRM.GetPage();
Response.Write(sHTML);
%>
Below are the descriptions of building blocks used in this code.
<!-- #include file ="sagecrm.js"-->
This building block specifies the include file that instantiates and initializes the CRM object. The include file also references the Sage CRM CSS, defines constants, and checks for errors. Depending on the scripting language you use, you can specify one of the following include files in your code:
- SAGECRM.JS. Referenced in JavaScript-based ASP pages. This file sets the default language to JavaScript.
- SAGECRMNOLANG.JS. Doesn't set the default language.
- SAGECRM.VBS. Referenced in Visual Basic-based ASP pages. This sets the default language to VB Script.
- eWare.JS. For backward compatibility with Sage CRM versions older than 5.6.
- ACCPACCRM.JS. For backward compatibility with Sage CRM versions older than 7.0.
- ACCPACCRMNOLANG.JS. For backward compatibility with Sage CRM versions older than 7.0.
- ACCPACCRM.VBS. For backward compatibility with Sage CRM versions older than 7.0.
<%
// Get an empty container block.
var SearchContainer = CRM.GetBlock('Container');
In this building block, ASP delimiters <% %> tell the ISAPI.DLL that the contained ASP code executes on the server.
The GetBlock(BlockName) method initializes a child block that implements core CRM functionality.
The GetBlock(BlockName) method parameter value is Container, which indicates the CRMContainerBlock object. This object groups and correctly displays output from other objects on the page. The Container block also provides default onscreen elements, such as buttons, that make it easier to format and support custom layouts.
The returned CRMContainerBlock object is stored in the variable SearchContainer. The Container screen contains only default buttons. To make it useful, add some blocks.
var SearchBlock = CRM.GetBlock('PersonSearchBox');
The GetBlock(BlockName) method retrieves a block and its associated functionality. This code specifies PersonSearchBox which is an instance of the CRMEntryGroupBlock object. To edit the contents of PersonSearchBox, go to <My Profile> | Administration | Customization | Person | Screens | Person Search Screen. Other standard screens based on the CRMEntryGroupBlock object include CompanySearchBox, PersonEntryBox, and CaseDetailBox.
SearchContainer.AddBlock(SearchBlock);
Add SearchBlock, an instance of PersonSearchBox, to the screen container.
// Change the label and image on the default button.
SearchContainer.ButtonTitle = 'Search';
SearchContainer.ButtonImage = 'Search.Gif';
This building block changes the attributes of the Save button. The Container object creates this by default.
// If button has been pressed then add the list block to show search results.
if (CRM.Mode == 2)
{
var resultsBlock = CRM.GetBlock('PersonGrid');
resultsBlock.ArgObj = SearchBlock;
SearchContainer.AddBlock(resultsBlock);
}
CRM.Mode == 2 displays a search results grid when a form is submitted.
The GetBlock(BlockName) method returns a PersonGrid block. PersonGrid is an instance of the CRMListBlock object. To view the fields displayed in this list, go to <My Profile> | Administration | Customization | Person | Lists | Person Grid.
The returned PersonGrid block is stored in the resultsBlock variable.
The CRMBlock object's property ArgObj, which is a base property implemented by all subclasses (such as the PersonGrid block), passes SearchBlock as a parameter for populating the list. This means that the list resultsBlock takes the search screen SearchBlock as a parameter, and the contents of the list generated by resultsBlock are determined by the values of the fields on the search screen SearchBlock.
The CRMContainerBlock object's AddBlock(Block) method adds the resultsBlock object.