Programmatically Enabling a Person for Self Service

1 minute read time.

A customer had the requirement to automatically enable a person record for Self Service. Normally a user would enable a Person as a Self Service contact from within the main user interface.

So what happens when the CheckBox is clicked?

If you look at the Self Service page under a Person, that information is not held in the Person Table. There is no field in the person table that holds the value of the CheckBox. Whether or not a person is enabled for Self Service is dynamically determined by a check for a record in the Visitor table in the Self Service database.

e.g.


select * from Visitor where Visi_PersonId=30

When you enter the Self Service screen this SQL is run against the visitor table in the Self Service database. The value of the personid matched against the visitor records comes from the person record in context.

If the CheckBox is 'checked' and the save button is clicked then a Self Service record is created by having a record added to the visitor table.

e.g.


INSERT INTO Visitor(Visi_PersonId,Visi_CompanyId,visi_logonid,visi_password,visi_language,Visi_FirstName,Visi_LastName,Visi_EmailAddress)  VALUES (30,28,N'Yaltoy',N'Yaltoy',N'US',N'Simon',N'Yaltoy',N'[email protected]')

If the person is already marked for self service access and the checkbox is unchecked, then corresponding record in the self service database is deleted.


DELETE FROM Visitor WHERE Visi_Personid=30

This means that if you want to automate the creating of self service records then you would need to use a version of the following code.


//Helper Function
function makePassword() {
var strPassword = '';
var strChars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
for (i=1;i","visi_personid="+intPersonId);
if (visiRecord.eof)
{
visiRecord = CRM.CreateRecord("TableName");
visiRecord.Visi_PersonId = personRecord.pers_personid;
visiRecord.Visi_CompanyId = personRecord.pers_companyid;
visiRecord.visi_logonid = personRecord.pers_lastname+intPersonId;
visiRecord.visi_password = makePassword(); 
visiRecord.visi_language = "US"
visiRecord.Visi_FirstName = personRecord.pers_firstname;
visiRecord.Visi_LastName = personRecord.pers_lastname;
visiRecord.Visi_EmailAddress = personRecord.pers_emailaddress;
}

This generates the logonid for the visitor based on their surname and their primary key. The password is automatically generated using the 'makepassword' function that I discussed in the article. Code to Generate a Pseudo-Random Password

Note: The code assumes that the ASP page is being run within the main interface.