Create an ASP page to display a single record

This example creates an ASP page to display a single record in the new table if it doesn't already exist.

  1. Create a custom ASP page to view and edit installed base records whose name matches the name specified in the tab group for Company. You can start with a sample Entry Group ASP page and include statements in the main block of the ASP page.
  2. Retrieve the identifier value for the current Company and store it in a variable.
    Copy
    CompanyId = CRM.GetContextInfo("Company","Comp_CompanyId");
  3. Create an instance of the installed base screen and assign it to a variable.
    Copy
    InstallBase = CRM.GetBlock("Install Base Details");
  4. Create a record for the installed base record and specify which record to display. See if the record already exists. If it doesn't, create a new record.
    Copy
    record = CRM.FindRecord("InstallBase","companyid="+CompanyId); 

    if (record.eof) {
      record = CRM.CreateRecord("InstallBase");
      record("CompanyId") = CompanyId;
      InstallBase.Title = "New Install Base Details";
  5. Display the screen using the record as the argument.
    Copy
    CRM.AddContent(InstallBase.Execute(record)); 
    Response.Write(CRM.GetPage());
  6. This allows the user to add or edit installed base details for each customer by clicking on the Installed Base tab for a Company. The first time the tab is selected, a record is added for the Company. Thereafter, when the tab is selected, the record is shown for editing.

Here's the installbase.asp script.

Copy
<!-- #include file ="sagecrm.js" -->

<%

// Get the Id of the current company.
CompanyId = CRM.GetContextInfo("Company","Comp_CompanyId");

// Create the Screen Block.
InstallBase = CRM.GetBlock("Install Base Details");

// Find the record in the table for this company.
record = CRM.FindRecord("InstallBase","Inst_CompanyId="+CompanyId);

if (record.eof) 
    {
        // If the record does not exist then create one and set the company ID.
        record = CRM.CreateRecord("InstallBase");
        record("Inst_CompanyId") = CompanyId;
        InstallBase.Title = "New Install Base Details";}
    
    else 
    
    {
        InstallBase.Title = "Edit Install Base Details";
    }
    
if (CRM.Mode <= 1
    {
         CRM.Mode = 1;
    }

// Display the record.
CRM.AddContent(InstallBase.Execute(record));
Response.Write(CRM.GetPage());

%>