This example consists of two CSP pages. Create GetLicenseKeys.csp, and ManageLicenseKey.csp. Copy the corresponding code from below into the CSP pages. Start the example with GetLicenseKeys.csp.
Note: Before running the example see "To use sample files" in Examples (JavaScript).
<link REL=STYLESHEET TYPE='text/css'>
<!-- #include file=helper_js.csp -->
<!-- #include file=ceconstjs.inc -->
// This page is the first page in the example. It provides a form
// that shows all license keys in the APS. The user can
// then select a license key to display, remove or add.
// Retrieve a list of all licenses on the APS. Return the list
// in an HTML string that will draw a drop down box.
// IStore - The InfoStore object.
("SELECT SI_ID, SI_LICENSE_KEY FROM CI_SYSTEMOBJECTS WHERE SI_PROGID='CrystalEnterprise.LicenseKey'");
return "There are no licenses to display.";
var HTMLTable="<select name=LicenseKeyId>";
// Iterate through all licenses and build the drop down box.
for (k=1;k<=Licenses.Count;k++)
License = Licenses.Item(k).PluginInterface("");
HTMLTable = HTMLTable + "<option value='"+Licenses.Item(k).Id+"'>"+License.LicenseKey;
HTMLTable= HTMLTable + "</select>";
Response.Write("The creation of the File event failed.");
//Retrieve the InfoStore object.
var IStore = GetSession("IStore");
// If the infostore object is not found then display an error message.
Response.Write ("Example failed: try logging on first!");
Response.Write ("<H2>License Key Management</H2>");
Response.Write ("<form action='ManageLicenseKey.csp' method=POST>");
Response.Write ("<B><FONT SIZE=+1>Add a new license key</FONT></B>");
Response.Write ("<P>Enter the license code and click Add:<BR>");
Response.Write("<input type=text name='LicenseKey' size=25 maxlength=21>");
Response.Write ("<BR><input type=submit name='Add' value='Add'><HR>");
Response.Write ("<B><FONT SIZE=+1>Display or remove a license key</FONT></B><P>");
Response.Write (GetLicenses(IStore));
Response.Write ("<P>Select the license key and click Display to view the properties:");
Response.Write ("<BR><input type=submit name='Display' value='Display'> ");
Response.Write ("<P>Select the license key and click Remove to delete:");
Response.Write ("<BR><input type=submit name='Remove' value='Remove'>");
<META HTTP
<!-- #include file=helper_js.csp -->
// This page is called from GetLicenseKeys.csp. Depending on the user's choice from
// - The license key will be added to the APS database.
// - The license key will be removed from the APS database.
// - The selected license key properties will be displayed.
//================================================
function AddLicenseKey (IStore, LicenseKey)
// This function adds a license key to the APS database.
// IStore - The InfoStore object.
// LicenseKey - The license key you want to add to the APS database.
var PluginMgr = IStore.PluginManager;
var LicenseKeyPlugin = PluginMgr.PluginInfo("CrystalEnterprise.LicenseKey");
// Create a new InfoObjects collection. This will be used to store the new object
// that will be commmitted later.
var NewInfoObjects = IStore.NewInfoObjectCollection();
// Add the result of the plugin. This will create a new InfoObject that
var NewLicenseKey = NewInfoObjects.Add (LicenseKeyPlugin);
// Get the LicenseKey plugin interface.
var CELicenseKey = NewLicenseKey.PluginInterface("");
Response.Write("Adding: " + LicenseKey);
CELicenseKey.LicenseKey = LicenseKey;
// Commit the collection, in which the new license key is stored, to the APS.
IStore.Commit (NewInfoObjects);
Response.Write ("<BR>Error ");
function DeleteLicenseKey (IStore, LicenseKeyId)
// This function deletes the selected license key from the APS database.
// IStore - The InfoStore object.
// LicenseKeyId - The InfoObject ID of the selected license key.
// Query for the selected license key.
var LicenseKeys = IStore.Query
("Select SI_ID, SI_LICENSEKEY From CI_SYSTEMOBJECTS Where SI_ID=" + LicenseKeyId);
var CELicenseKey = LicenseKeys.Item(1);
// Delete the License Key by passing the LicenseKey's InfoObject ID.
LicenseKeys.Delete(CELicenseKey);
// Commit the information to the APS.
Response.Write ("<BR>Error ");
function DisplayLicenseKey (IStore, LicenseKeyId)
// This function displays the selected license key's properties.
// IStore - The InfoStore object.
// LicenseKeyId - The InfoObject ID of the selected license key.
// Returns: The table displaying the license key properties.
// Query for the selected license key.
var LicenseKeys = IStore.Query
("Select Top 1* From CI_SYSTEMOBJECTS Where SI_ID=" + LicenseKeyId);
// Get the LicenseKey plugin interface.
var LicenseKey = LicenseKeys.Item(1).PluginInterface("");
// Create a table to display the license key properties.
var HTMLTable = "<Table BORDER=0 CELLPADDING=3 CELLSPACING=3>";
HTMLTable = HTMLTable + "<TD><B>Product level:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.ProductLevel+ "</TD>";
HTMLTable = HTMLTable + "<TD><B>Product name:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.ProductName + "</TD>";
HTMLTable = HTMLTable + "<TD><B>Product version:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.ProductVersion + "</TD></TR>";
HTMLTable = HTMLTable + "<TR><TD><B>Expiry date:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.ExpiryDate + "</TD>";
HTMLTable = HTMLTable + "<TD><B>Language:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.Language + "</TD></TR>";
HTMLTable = HTMLTable + "<TR><TD><B>License count:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.LicenseCount + "</TD>" ;
HTMLTable = HTMLTable + "<TD><B>License type:</B></TD>";
HTMLTable = HTMLTable + "<TD>" + LicenseKey.LicenseType + "</TD></TR>";
HTMLTable = HTMLTable + "</Table>";
Response.Write ("<BR>Error ");
//================================================
//Retrieve the InfoStore object.
var IStore = GetSession("IStore");
// If the infostore object is not found then display an error message.
Response.Write ("Example failed: try logging on first!");
LicenseKeyId = Request.Form.Item("LicenseKeyId");
if(Request.Form.Item("Add")=="Add")
var LicenseKey = Request.Form.Item("LicenseKey");
AddLicenseKey (IStore, LicenseKey);
Response.ReDirect("GetLicenseKeys.csp");
if (Request.Form.Item("Remove")=="Remove")
DeleteLicenseKey (IStore, LicenseKeyId);
Response.ReDirect("GetLicenseKeys.csp");
if(Request.Form.Item("Display")=="Display")
Response.Write ("<form action='GetLicenseKeys.csp' method=POST>");
DisplayLicenseKey (IStore, LicenseKeyId);
Response.Write ("<P><input type=submit name='Back' value='Back'>");
Crystal Decisions, Inc. http://www.crystaldecisions.com Support services: http://support.crystaldecisions.com |