Creating and controlling Edit Pages in Self Service

1 minute read time.

Below is a very simple example of a self service page that allows a case belonging to an authenticated visitor to be edited.

The ASP code is found below. The code is comment and discussed.




" HREF=\"eware.css\">";
var Body="";
var EndBody="";
Response.Write(Head);
Response.Write(Body);
if (CRM.Authenticated)
{
//Grabbing CaseID from QueryString
var strKeyID= "case_caseid";
var Id = new String(Request.Querystring(strKeyID));
var intCaseId = 0;
if (Id.indexOf(",") > 0)
{
   var Idarr = Id.split(",");
   intCaseId = Idarr[0];
}
else if (Id != "")
{
  intCaseId = Id;
}
//Uses Self Service User context to retrieve Person data.
var intRecordId = CRM.VisitorInfo("visi_personid");
var PersonRecord = CRM.FindRecord('person','pers_personid='+intRecordId);
//A very basic check to ensure that authenticated users can only see their own records.
//and Unauthenticated visitors have no access
var CaseRecord = CRM.FindRecord('cases','case_primarypersonid = '+ intRecordId+ ' and case_caseid='+intCaseId);
if (!CaseRecord.eof)
{
//Control and Setting Properties of Entry Blocks
var myBlock = CRM.GetBlock("sscaseentry");
//myBlock.Title = CRM.GetTrans("tabnames","cases");
var entryBlock = myBlock.GetEntry("case_problemnote");
var entryDescription = myBlock.AddEntry("case_description",1,false);
var entrySource = myBlock.AddEntry("case_source",-1,true);
var entryCustomerRef = myBlock.AddEntry("case_customerref",-1,true);
entryCustomerRef.NewLine = false;
 
var strHTML = myBlock.Execute(CaseRecord);
if (CRM.Mode == Save)
{
Response.Redirect("customcases.asp");
}
else
{
Response.Write(strHTML);
}
}
else
{
Response.Write("No Record Found");
}
}
else
{
  Response.Redirect("customlogon.asp");
}
////////////////////
Response.Write(EndBody);
%>

Grabbing CaseID from QueryString

A hyperlink from a list block in Self Service will typically pass the target records primary key value in the query string.

Basic Security Check

Because the target record ID is included in the querystring URL a double check has to be made that the person looking for the record is entitled to view the record. Without a check that includes the authenticated Visitor's ID anyone could go on a data fishing expedition.

Control and Setting Properties of Entry Blocks

This section shows that you can edit the consituent fields (entry blocks) of a screen (EntryGroup) block. You can remove and add new fields programmatically and you can set properties such as NewLine easily.