Tutorial — Creating New Objects

A “Person” Class for Siebel

Introduction

In working with Subscription Lists, the User is sometimes a Contact and sometimes a Prospect. Siebel records that reference Contacts and Prospects use different Foreign Key (FK) fields depending on the User type. For example, the Contact FK is the [Contact Id] field, while the Prospect FK is the [Prospective Contact Id] field.

This all means that record operations for a given User require using the appropriate field for that type of User. One might use a flag variable combined with if/else statements. Or just have the if/else detect whether one of two variables is empty or not.

An indirect technique passes both the Id and the fieldname to the function that does the work. That function uses the fieldname when activating the field, searching on the FK or accessing the field itself.

function GetUserInfo (personId,personFieldname, firstName,lastName,personEmail)
{
  var listBC = listBO.GetBusComp("List Mgmt List Member")
  with (listBC)
  {
    SetViewMode (AllView);
    ActivateField (personFieldname);
    ClearToQuery ();
    SetSearchSpec (personFieldname, personId);
    ExecuteQuery (ForwardOnly);
    if (FirstRecord())
    {
      personEmail = GetFieldValue ("Email Address");
      firstName   = GetFieldValue ("First Name");
      lastName    = GetFieldValue ("Last Name");
    }
  }
  listBC = null;
}

Passing two variables (and perhaps more as outputs) tends to generate clutter. An object makes an elegant data package–it's sorta the whole idea!

A new JavaScript Object

In this example, a JavaScript object replaces the “person” variables.

function SiebelPerson (t,id)
{
  this.type = t;
  this.id = id;
  this.email = "";
  this.UserName = "";
  this.firstName = "";
  this.lastName = "";
  this.fieldName = t + " Id";
}

Create a new one like this:

var  person = new SiebelPerson ("Contact", contactId);

Now the indirect technique looks like this:

function GetUserInfo (person)
{
  var listBC = listBO.GetBusComp("List Mgmt List Member")
  with (listBC)
  {
    SetViewMode (AllView);
    ActivateField (person.fieldName);
    ClearToQuery ();
    SetSearchSpec (person.fieldName, person.id);
    ExecuteQuery (ForwardOnly);
    if (FirstRecord())
    {
      person.email     = GetFieldValue ("Email Address");
      person.firstName = GetFieldValue ("First Name");
      person.lastName  = GetFieldValue ("Last Name");
    }
  }
  listBC = null;
}

You might use it like this:

var  person = new SiebelPerson ("Prospect", prospectId);
GetUserInfo (person);

print "Name = " + person.firstName + " " + person.lastName;
print "Email = " + person.email;

(One thing missing from all this is error detection. The code makes no provisions for not finding a user.)