Create ASP pages to display multiple records

This example creates ASP pages to display multiple records in the new table for each customer. It creates two custom pages; one to view a list of records and another to jump to individual records.

  1. Create a custom page whose name matches the name specified in the tab group for Company. For a sample Entry Group ASP page, see Create an ASP page to display a single record .
  2. Include statements in the main block of the ASP page to perform the following tasks.
    • Retrieve the identifying value for the current Company and assign it to a variable.

      CompanyId = CRM.GetContextInfo("Company","Comp_CompanyId");

    • Create a block for the Installed Base List and assign it to a variable. The list name is the name of the list created in Step 3: Create a List object for installed base.

      InstallBase = CRM.GetBlock("installbaselist");

    • Write the list to the screen by executing the List block, telling it to show records for this company only.

      CRM.AddContent(InstallBase.Execute("Inst_CompanyId="+ThisCompany));

    • Add a New button to the screen to allow new records to be added. This calls another ASP page.

      CRM.AddContent(CRM.Button("New","new.gif",CRM.Url("InstallBaseEdit.asp")));
      Response.Write(CRM.GetPage());

  3. Create another custom page to jump to view/edit/delete individual records. The page name is the name of the page specified in Custom Action File in Step 3: Create a List object for installed base.
  4. Include statements in the main block of the ASP page to perform the following tasks:
    • Retrieve the ID value of the record that's viewed from the Query string.

      ThisInstallBase = Request.QueryString("Inst_InstallBaseId");

    • Create a block for the Installed Base screen and assign it to a variable.

      InstallBaseItem = CRM.GetBlock("InstallBaseDetailsBox");

    • Turn on the Delete button on the block to allow existing records to be deleted.

      DisplayButton(Button_Delete) = true;

    • Turn on the Continue button to allow users to return to the list.

      DisplayButton(Button_Continue) = true;

    • Check if this is an existing record or if a new record must be created. Create the Record object if required. If it's a new record, the exact Company ID must be set and it must go straight into edit mode.

      if (!Defined(ThisInstallBase)) {
      CompanyId = CRM.GetContextInfo("Company","Comp_CompanyId");
      InstallBaseRecord = CRM.CreateRecord("InstallBase"); InstallBaseRecord("Inst_CompanyId") = CompanyId;
      }
      if (CRM.Mode <= Edit) {
      CRM.Mode = Edit;
      }
      else {
      InstallBaseRecord = CRM.FindRecord("InstallBase","Inst_InstallBaseId="+ThisInstallBase);
      }

  5. Display the block, passing in the Record object. Note that the edit/delete/add functionality is handled by the block internally.

The Installbaselist.asp script is displayed below.

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

// Get the value of the current Company ID.
ThisCompany = CRM.GetContextInfo("Company","Comp_CompanyId");

// Create the List Block.
InstallBase = CRM.GetBlock("installbaselist");

// Display the List.
CRM.AddContent(InstallBase.Execute("Inst_CompanyId="+ThisCompany));

// Add the New button to allow user to add new records for this company.
CRM.AddContent(CRM.Button("New","new.gif",CRM.Url("InstallBaseEdit.asp")));
Response.Write(CRM.GetPage());

%>