Extracting data about an EntityDef (record type)
To illustrate that you can manipulate metadata, the following example of an external application prints the following:
- The name of the EntityDef
- The names and types of each field and action it contains
- The names of each state it contains
This subroutine makes use of a routine called StdOut, which prints its arguments to a message box.
VBScript
Sub DumpOneEntityDef(edef) ' the parameter is an EntityDef object
Dim names ' a Variant
Dim name ' a String
Dim limit ' a Long
Dim index ' a Long
StdOut "Dumping EntityDef " & edef.GetName
StdOut " FieldDefs:"
names = edef.GetFieldDefNames
If IsArray(names) Then
index = LBound(names)
limit = UBound(names) + 1
Do While index < limit
name = names(index)
StdOut " " & name & " type=" & edef.GetFieldDefType(name)
index = index + 1
Loop
End If
names = edef.GetActionDefNames
If IsArray(names) Then
index = LBound(names)
limit = UBound(names) + 1
Do While index < limit
name = names(index)
StdOut " " & name & " type=" & _
edef.GetActionDefType(name)
index = index + 1
Loop
End If
If edef.GetType() = AD_REQ_ENTITY Then
' stated record type
StdOut " EntityDef is a REQ entity def"
StdOut " StateDefs:"
names = edef.GetStateDefNames
If IsArray(names) Then
index = LBound(names)
limit = UBound(names) + 1
Do While index < limit
name = names(index)
StdOut " " & name
index = index + 1
Loop
End If
Else
' stateless record type
StdOut " EntityDef is an AUX entity def"
End If
StdOut ""
End Sub
REM Start of Global Script StdOut
sub StdOut(Msg)
msgbox Msg
end sub
REM End of Global Script StdOut
Perl
use strict;
use CQPerlExt;
my $sessionObj = CQSession::Build();
$sessionObj->UserLogon("admin", "", "SAMPL", "");
my $entityDefNames = $sessionObj->GetEntityDefNames();
#Iterate over the record types
foreach my $edef_name (@$entityDefNames) {
my $entityDefObj = $sessionObj->GetEntityDef($edef_name);
print_edef($entityDefObj);
}
sub print_edef {
my($edef)=@_;
# The parameter is an EntityDef object.
my($names, $name);
print "Dumping EntityDef ", $edef->GetName;
print "\nFieldDefs:";
$names = $edef->GetFieldDefNames;
foreach $name (@$names) {
print " " , $name , " type=" ,
$edef->GetFieldDefType($name);
}
print "\nActionDefs: ";
$names = $edef->GetActionDefNames;
foreach $name (@$names) {
print " " , $name , " type=" ,
$edef->GetActionDefType($name);
}
if ($edef->GetType == $CQPerlExt::CQ_REQ_ENTITY) {
# stated record type
print "\nEntityDef is a REQ entity def";
print "\nStateDefs:";
$names = $edef->GetStateDefNames;
foreach $name (@$names) {
print " " , $name;
}
}
else {
# stateless record type
print "\nEntityDef is an AUX entity def";
}
print "\n\n";
}
CQSession::Unbuild($sessionObj);