Monday, March 17, 2008

Siebel COM programming with Perl

I wanted to play around with the Siebel COM interface using a dynamic language instead of having to re-compile after every change. I happened to have perl installed on my machine so it was the natural choice. Since google didn't show me any usable hits beforehand and it took a bit of investigation, I'm posting my results here.

#!c:/perl/bin/perl.exe -w
use strict;
use Win32::OLE;
use Win32::OLE::Variant;

my $schema = {
'Contact' => [
'Birth Date', 'Created', 'Created By Name', 'Email Address', 'Fax Phone #',
'First Name', 'Id', 'Job Title', 'Last Name', 'Updated', 'Updated By Name',
'Work Phone #']

my $cfg = "C:/sea/client/OBJECTS/siebel.cfg";

my $sa = Win32::OLE->new("SiebelDataServer.ApplicationObject") or die "failed";

sub x
my ($tag, $rc) = @_;
if ($rc != 0) {warn("[$tag] " . $sa->GetLastErrText());}

sub main
my ($bo, $bc, $key, $field, $moreResults, $rcref);

$rcref = Variant(VT_I2|VT_BYREF, 0);
$sa->LoadObjects($cfg, $rcref); &x("a", $rcref);
$sa->Login("user", "password", $rcref); &x("b", $rcref);

foreach $key (keys(%$schema)) {
$bo = $sa->GetBusObject($key, $rcref); &x("c", $rcref);
$bc = $bo->GetBusComp($key, $rcref); &x("d", $rcref);
foreach $field (@{$schema->{$key}}) {
$bc->ActivateField($field, $rcref); &x("e", $rcref);
$bc->ClearToQuery($rcref); &x("f", $rcref);
$bc->SetSearchExpr("[Email Address] IS NOT NULL AND [Last Name] LIKE 'R*'", $rcref);
&x("g", $rcref);

$bc->ExecuteQuery(1, $rcref); &x("h", $rcref);
$moreResults = $bc->FirstRecord($rcref); &x("i", $rcref);
while ($moreResults) {
foreach $field (@{$schema->{$key}}) {
printf ("%40s: %s\n",$field, $bc->GetFieldValue($field, $rcref));
&x("j", $rcref);
$moreResults = $bc->NextRecord($rcref); &x("k", $rcref);


Charles said...

Cool! Great example. I've used Perl for many Siebel related things, but there are very few examples on the web... none that I know of for the COM interface. (

Stefano said...

Great Stuff! I will try something similar with Ruby :)

Alceu Rodrigues de Freitas Junior said...

Great to have an example in Perl, specially considering that Oracle put in the Siebel Bookshelf exactly this: "You cannot use the Perl programming language to access a Siebel COM interface." (see which in this case is plain bullshit, they simply do not considered reading the POD for Win32::OLE::Variant.

Artur Kowalsky said...
This comment has been removed by the author.
Acop PL said...

Great job..
I was just looking for such an inspiration.
Now there is also inspired by you ;) Which I hope to check out quite soon..

2 more reasons found today to love Perl (blog entry and perl module) :)