Monday, March 17, 2008

Siebel COM programming with Groovy

After my success in using Perl to program the siebel COM interface, I thought I'd try groovy. Yes it works as well.

import org.codehaus.groovy.scriptom.*

Scriptom.inApartment
{
def sa = new ActiveXObject('SiebelDataServer.ApplicationObject');
VariantByref rc = new VariantByref(0 as short);

sa.LoadObjects("C:/sea/client/OBJECTS/siebel.cfg", rc);
(rc.value == 0) || println("a: " + sa.GetLastErrText())

sa.Login("user", "password", rc)
(rc.value == 0) || println("b: " + sa.GetLastErrText())

def bo = sa.GetBusObject("Contact", rc)
(rc.value == 0) || println("c: " + sa.GetLastErrText())

def bc = bo.GetBusComp("Contact", rc);
(rc.value == 0) || println("d: " + sa.GetLastErrText())

bc.ClearToQuery(rc);
(rc.value == 0) || println("e: " + sa.GetLastErrText())

bc.ActivateField("Birth Date", rc);
(rc.value == 0) || println("f: " + sa.GetLastErrText())

bc.ActivateField("First Name", rc);
(rc.value == 0) || println("g: " + sa.GetLastErrText())

bc.ActivateField("Last Name", rc);
(rc.value == 0) || println("h: " + sa.GetLastErrText())

bc.ActivateField("Id", rc);
(rc.value == 0) || println("i: " + sa.GetLastErrText())

bc.SetSearchExpr("[Birth Date] = 01/01/1900 AND [Last Name] LIKE 'R*'", rc)
(rc.value == 0) || println("j: " + sa.GetLastErrText())

bc.ExecuteQuery(true, rc);
(rc.value == 0) || println("k: " + sa.GetLastErrText())

def moreRecords = bc.FirstRecord(rc);
(rc.value == 0) || println("l: " + sa.GetLastErrText())

while(moreRecords) {
println " Last Name: " + bc.GetFieldValue("Last Name", rc);
(rc.value == 0) || println("m: " + sa.GetLastErrText())
println "First Name: " + bc.GetFieldValue("First Name", rc);
(rc.value == 0) || println("n: " + sa.GetLastErrText())
println "Birth Date: " + bc.GetFieldValue("Birth Date", rc);
(rc.value == 0) || println("o: " + sa.GetLastErrText())
println " Id: " + bc.GetFieldValue("Id", rc);
(rc.value == 0) || println("p: " + sa.GetLastErrText())
moreRecords = bc.NextRecord(rc);
}

println 'Done'
}

No comments: