Print Business Object

You can use the Print Businessobject command and the Select Businessobject command to view the definition of a business object.

This page discusses:

Syntax

These commands enable you to view all the files and information used to define the business object. The system attempts to produce output for each Select clause input, even if the object does not have a value for it. If this is the case, an empty field is output.

print businessobject OBJECTID [select SELECTABLE] [DUMP ["SEPARATOR_STR"]] [output FILENAME] [sortattributes];
print businessobject selectable;
print businessobject selected;
select businessobject SELECT;

When this command is processed, MQL displays all information that makes up the named business object’s definition. This information appears in alphabetical order according to names of the object’s fields. For example, you could obtain the definition for the “Shipping Form” “Lyon’s Order” A business object by entering:

print businessobject “Shipping Form” “Lyon’s Order” A;

The Print Businessobject command uses four optional Print command clauses:

The optional forms of the Print Businessobject command let you specify the information you want to retrieve from a business object. This subset is created by identifying the desired fields of the business object. The field contents can be prepared for formatting and stored in an external file. But which fields can you print and how do you specify them? The Print Businessobject Selectable command addresses these questions. This command lets you view a listing of field choices and specify those choices.

Reviewing the List of Field Names

The first step is to examine the general list of field names:

print businessobject selectable;

The Selectable clause is similar to using the ellipsis button in the graphical applications—it provides a list from which to choose.

When the command above is processed, MQL lists all selectable fields with their associated values. This command might produce a listing such as:

business object selectable fields:
   name
   description
   revision
   originated
   modified
   lattice.*
   owner.*
   grant.*
   grantor.*
   grantee.*
   granteeaccess
   granteesignature
   grantkey
   policy.*
   type.*
   attribute[].*
   default.*
   format[].*
   current.*
   state[].*
   revisions[].*
   previous.*
   next.*
   first.*
   last.*
   history[].*
   relationship[].*
   to[].*
   from[].*
   toset[].*
   fromset[].*
   exists
   islockingenforced
   vault.*
   locked
   locker.*
   id
   method.*
   search.*
   cestamp
   updatestamp

Some of the fields are followed by square brackets and/or a " .* ". The asterisk denotes that the field can be further expanded, separating the subfields with a period. If only one value is associated, the name appears without an asterisk. For example, the Name and Description fields each have only a single value that can be printed. On the other hand, a field such as type has other items that can be selected. If you expand the Type field, you might find fields such as type.name , type.description , and type.policy . This means that from any business object, you could select a description of its type and find out other valid policies for it:

print businessobject Drawing 726590 B select type.description type.policy;

The above might output something like this:

business object Assembly 726590 B
   type.description = Assembly of parts
   type.policy = Production
   type.policy = Production Alternative

All items that can be further expanded have a default subfield that is used when that field is specified alone. For example, selecting type is the same as selecting type.name, because the default for types is the type name. For more information, see the Appendix: Selectables.

The use of square brackets in the above selectable list indicates one of two things:

  • The assigned name can also be included as part of the selection. For example, an object generally has several attributes. To select a particular attribute, you must give the assigned name of the attribute as part of the field name.
    print bus Component 45782 A select attribute[Color];

    If you select attribute without specifying anything, a list of all attributes with their values are returned. The same is true for state, format, relationship, and so on.

  • The default value of an attribute can be printed by selecting the attribute value. For example, the default value can be output using this command.
    print businessobject T N R select attribute[attributeName].value;
    If the attribute has a default value, the value is returned. If the attribute is defined as !hasdefault, an empty string is returned.
  • To differentiate between the unset value of a string attribute and an empty string value, you can use the isset selectable. You can use this to identify if an attribute is defined as !hasdefault. For example, you can identify is a value is defined for an attribute using the following command.
    print businessobject T N R select attribute[attributeName].isset;
    If an attribute is defined as !hasdefault, FALSE is returned. For other attributes, TRUE is returned.
  • With the from and to selectables only, you can provide a comma delimited list of patterns that can include wildcard characters, as a means of filtering on relationship names and connected object types. For example:
    print bus Guide “Owners Manual” 2004 select to[N*,S*].from.name to[N*,S*].from.revision;

    This command might return something like this:

    business object Guide Owners Manual 2004
        to[New].from[Chapter].name = Chapter 2
        to[New].from[Photo].name = ‘2004 Red Camry’
        to[Same].from[Chapter].name = Chapter 4
        to[New].from[Chapter].revision = 5
        to[New].from[Photo].revision = 1
        to[Same].from[Chapter].revision = 2

For more information, see Expand Business Object.

Once you have identified names of the fields that can be printed, you can select them. The Select Businessobject statement tags the items to be shown in a subsequent Print statement. This is like creating a form in Business Administrator where you decide what collection of information to display. The Print statement is then comparable to displaying the form in a web app.

print OBJECT_ID select FIELD_NAME {FIELD_NAME};

  • + appends field names to the currently selected field names. If no fields are currently selected, the select creates a new list from FIELD_NAMEs.
  • FIELD_NAME can be a string, list of strings, or wildcard character (*) that represents a printable field value associated with a business object. Each field name obeys the following syntax:
    FIELD_NAME [ASSIGNED_NAME_PATTERN].SUBFIELD_PATTERN
  • ASSIGNED_NAME_PATTERN is the name assigned to the field when it is created. This name, when required, must be within square brackets.
  • SUBFIELD_PATTERN is the specification of another field. This field is a part of the larger field specification. All subfield names are preceded by a period and often correspond to the clauses that make up a field definition.

For example:

select businessobject name description type;

This select command is added as a clause to the Print Businessobject command:

print businessobject Drawing 726596 B select name description type.name;

This yields:

business object Drawing 726596 B
   name = 726596
   description = Piston Assembly
   type.name = Drawing

The fields appear in the order they were specified in the Select clause.

Sortattributes Clause

When printing business objects, the Sortattributes clause causes the command to list attributes in the same order as in 3DSpace.

Connection Selectables

The frommid and tomid selectables on the Print Connection command allow you to print information on the FROM and TO ends of a relationship.

For example, the following commands create a set of objects with relationships that connect objects to objects, objects to relationships, relationships to objects, and relationships to relationships. They then execute print/query commands with the corresponding selectables.

# 
#  Creates this structure: 
# 
#  A1 ------rx------> A2 ------rx------> A3 ------rx------> A4 
#   \       |    \ 
#    \      |     \ 
#    o2r   r2r   r2o 
#      \    |       \ 
#       \   |        \ 
#  B1 ------rx------> B2

set context user creator; 
add vault unit1; 
add attribute string-u type string; 
add attribute rstring-u type string; 
add type tx attribute string-u; 
add policy px type tx state one state final; 
add rel rx from type tx to  type tx attribute rstring-u; 
add rel r2o from rel rx to type tx attribute rstring-u; 
add rel o2r from type tx to rel rx attribute rstring-u; 
add rel r2r from rel rx to rel rx attribute rstring-u;

add bus tx A1 0 policy px vault unit1 string-u A1-attr; 
add bus tx A2 0 policy px vault unit1 string-u A2-attr; 
add bus tx A3 0 policy px vault unit1 string-u A3-attr; 
add bus tx A4 0 policy px vault unit1 string-u A4-attr; 
add bus tx B1 0 policy px vault unit1 string-u B1-attr; 
add bus tx B2 0 policy px vault unit1 string-u B2-attr;

connect bus tx A1 0 rel rx to tx A2 0 rstring-u A1-A2; 
connect bus tx A2 0 rel rx to tx A3 0 rstring-u A2-A3; 
connect bus tx A3 0 rel rx to tx A4 0 rstring-u A3-A4; 
connect bus tx B1 0 rel rx to tx B2 0 rstring-u B1-B2; 
add connection o2r from tx A1 0 torel bus tx B1 0 to tx B2 0 rel rx rstring-u A1-rel; 
add connection r2o fromrel bus tx A1 0 to tx A2 0 rel rx to tx B2 0 rstring-u rel-B2; 
add connection r2r fromrel bus tx A1 0 to tx A2 0 rel rx torel bus tx B1 0 to tx B2 0 rel rx rstring-u rel-rel;

# Fromrel, torel show any relationships on the to/from end of "this" relationship. 
# Frommid, tomid show any relationships that have "this" relationship  to relationships 
# allow subselects to get data on the rels they map to. 
print bus tx A1 0 select from.attribute.value from.torel from.torel.attribute.value from.torel.from.name from.torel.to.name; 
query connection type rx,r2o,o2r,r2r select fromrel fromrel.attribute[rstring-u] torel torel.attribute[rstring-u]; 
query connection type rx,r2o,o2r,r2r select frommid frommid.attribute[rstring-u] tomid tomid.attribute[rstring-u];

# Fromall, toall show both businessobjects and rels (with a B or R prefix) 
# They query connection type rx,r2o,o2r,r2r select fromall toall;

# Cleanup 
del bus tx A1 0 ; 
del bus tx A2 0 ; 
del bus tx A3 0 ; 
del bus tx A4 0 ; 
del bus tx B1 0 ; 
del bus tx B2 0 ; 
del rel rx; 
del rel r2o; 
del rel o2r; 
del rel r2r; 
del policy px; 
del type tx;


########################################################################### 
# HF-105472V6R2012_

tcl; 
set rxId ""
set o2rId ""
set obj2Id "" 
set lIds [split [mql print bus tx A1 0 select id from.id from.to.id] \n] 
foreach sId $lIds { 
  if {[string first "\[rx\].id" $sId] > 0} { 
    set rxId [string trim [lindex [split $sId =] 1]] 
  } 
  if {[string first "o2r" $sId] > 0} { 
    set o2rId [string trim [lindex [split $sId =] 1]] 
  } 
  if {[string first "\[rx\].to.id" $sId] > 0} { 
    set obj2Id [string trim [lindex [split $sId =] 1]] 
  } 
  set r2oId [mql print bus tx B2 0 select to\[r2o\].id dump] 
} 
puts "rxId=$rxId\no2rId=$o2rId\nobj2Id=$obj2Id\nr2oId=$r2oId"

# Bad command - changing TO from obj to rel 
mql start trans; 
mql mod connection $rxId torel $o2rId 
mql abort trans;

# Bad command - changing TO from rel to obj 
mql start trans; 
mql mod connection $o2rId to $obj2Id 
mql abort trans;

# Bad command - changing FROM from obj to rel 
mql start trans; 
mql mod connection $rxId fromrel $o2rId 
mql abort trans;

# Bad command - changing FROM from rel to obj 
mql start trans; 
mql mod connection $r2oId from $obj2Id 
mql abort trans;

# Cleanup 
del bus tx A1 0; 
del bus tx A2 0; 
del bus tx A3 0; 
del bus tx A4 0; 
del bus tx B1 0; 
del bus tx B2 0; 
del rel rx; 
del rel r2o; 
del rel o2r; 
del rel r2r; 
del type tx;

################################################################### 
# 
#  GENERATE XML OUTPUT FROM EXPAND COMMAND 
# 
expand bus tx A1 0 xml from recurse to all select bus attribute.value 
select rel type attribute.value frommid.attribute.value 
frommid.to.type frommid.to.name frommid.to.revision frommid.torel 
frommid.torel.attribute.value frommid.torel.from.name 
frommid.torel.to.name output testExpand.xml;

The output of the above commands is as follows:

MQL<100>add type tx attribute string-u; 
MQL<101>add policy px type tx state one state final; 
MQL<102>add rel rx from type tx to  type tx attribute rstring-u; 
MQL<103>add rel r2o from rel rx to type tx attribute rstring-u; 
MQL<104>add rel o2r from type tx to rel rx attribute rstring-u; 
MQL<105>add rel r2r from rel rx to rel rx attribute rstring-u; 
MQL<106>add bus tx A1 0 policy px vault unit1 string-u A1-attr; 
MQL<107>add bus tx A2 0 policy px vault unit1 string-u A2-attr; 
MQL<108>add bus tx A3 0 policy px vault unit1 string-u A3-attr; 
MQL<109>add bus tx A4 0 policy px vault unit1 string-u A4-attr; 
MQL<110>add bus tx B1 0 policy px vault unit1 string-u B1-attr; 
MQL<111>add bus tx B2 0 policy px vault unit1 string-u B2-attr; 
MQL<112>connect bus tx A1 0 rel rx to tx A2 0 rstring-u A1-A2; 
MQL<113>connect bus tx A2 0 rel rx to tx A3 0 rstring-u A2-A3; 
MQL<114>connect bus tx A3 0 rel rx to tx A4 0 rstring-u A3-A4; 
MQL<115>connect bus tx B1 0 rel rx to tx B2 0 rstring-u B1-B2; 
MQL<116>add connection o2r from tx A1 0 torel bus tx B1 0 to tx B2 0 rel rx rstring-u A1-rel; 
MQL<117>add connection r2o fromrel bus tx A1 0 to tx A2 0 rel rx to tx B2 0 rstring-u rel-B2; 
MQL<118>add connection r2r fromrel bus tx A1 0 to tx A2 0 rel rx torel bus tx B1 0 to tx B2 0 rel rx rstring-u rel-rel; 
MQL<119>print bus tx A1 0 select from.attribute.value from.torel from.torel.attribute.value 
from.torel.from.name from.torel.to.name; 
business object  tx A1 0
    from[o2r].attribute[rstring-u].value = A1-rel
    from[rx].attribute[rstring-u].value = A1-A2
    from[o2r].torel = rx
    from[o2r].torel.attribute[rstring-u].value = B1-B2
    from[o2r].torel.from.name = B1
    from[o2r].torel.to.name = B2 
MQL<120>query connection type rx,r2o,o2r,r2r select fromrel 
fromrel.attribute[rstring-u] torel torel.attribute[rstring-u]; 
relationship rx 
relationship rx 
relationship rx 
relationship rx 
relationship o2r
    torel = rx
    torel.attribute[rstring-u] = B1-B2 
relationship r2o
    fromrel = rx
    fromrel.attribute[rstring-u] = A1-A2 
relationship r2r
    fromrel = rx
    fromrel.attribute[rstring-u] = A1-A2
    torel = rx
    torel.attribute[rstring-u] = B1-B2

MQL<121>query connection type rx,r2o,o2r,r2r select 
frommid frommid.attribute[rstring-u] 
tomid tomid.attribute[rstring-u]; 
relationship rx 
relationship rx 
relationship rx
    frommid = r2o
    frommid = r2r
    frommid[r2o].attribute[rstring-u] = rel-B2
    frommid[r2r].attribute[rstring-u] = rel-rel 
relationship rx
    tomid = o2r
    tomid = r2r
    tomid[o2r].attribute[rstring-u] = A1-rel
    tomid[r2r].attribute[rstring-u] = rel-rel 
relationship o2r 
relationship r2o 
relatioship r2r 
MQL<122>query connection type rx,r2o,o2r,r2r select fromall 
fromall.attribute[rstring-u] toall toall.attribute[rstring-u]; 
relationship rx
    fromall = B2384.50535.15736.55350
    toall = B2384.50535.15736.54777
    relationship rx
    fromall = B2384.50535.15736.54777
    toall = B2384.50535.15736.32988 
relationship rx
    fromall = B2384.50535.15736.51305
    toall = B2384.50535.15736.55350 
relationship rx
    fromall = B2384.50535.15736.63113
    toall = B2384.50535.15736.6841 
relationship o2r
    fromall = B2384.50535.15736.51305
    toall = R2384.50535.15736.45609 
relationship r2o
    fromall = R2384.50535.15736.51178
    toall = B2384.50535.15736.6841
relationship r2r
    fromall = R2384.50535.15736.51178
    toall = R2384.50535.15736.45609

Revisions Selectable

The revisions[ ].revindex selectable is similar to other revision related selectables in that it returns a revision in the revision sequence. It returns revisions in between the first and last revisions. In the selectable you can specify the business object revision by its index. If the index is not available, this selectable will work like the next selectable and return no value.

Method and Program Selectables

The select keywords method and program can be used wherever select keywords for business objects can be used. They can be used in both print bus and in expressions evaluated against business objects. The syntax is:

program [PROGRAM_NAME ARG1 ARG2 …]
Or:
method [METHOD_NAME ARG1 ARG2 …]

  • PROGRAM_NAME is the name of a program.
  • METHOD_NAME is the name of a method.

Zero or more arguments can be included as indicated. The total number of characters in brackets is limited to 128.

The program keyword allows non-method programs to be run.

  • They can use the same macros as a method.
  • The arguments are space-delimited.
  • The program/method name must be quoted if it contains spaces.
  • Arguments containing spaces must be quoted or enclosed in {}.
  • If the program exits with a non-zero exit code, the select clause returns an empty string as a value.

The select clause returns a string whose value is specified by the program. The program specifies it by placing the string in the GLOBAL RPE variable whose name equals the program name. This is consistent with the use of a program to load a single valued text widget, except for having to use global.

As a select clause, this capability can be used in any of the following ways:

  • print bus T N R select owner current program[NAME] attribute[ATT] dump
  • To load Tcl variables via: set sVar [mql print bus ....]
  • As part of a where clause in a Query
  • As a column definition

Execute Selectable

You can use the select keyword execute in place of program to pass selectables as arguments to Tcl programs. Execute is a faster alternative to program because it passes selectable values directly into programs. For example, you can write:

temp query bus * * * where 'escape execute[X "arg0" attribute\[Z\]]==TRUE'

And then in the program X have:

tcl;
eval {
set arg0 ${1};
set data ${2};
...
return ${result};
}

The keyword escape in the above argument allows selectables to be passed in the bracketed portion of the execute selectable. There is no need to call get env or set env global. Arguments specified with execute in this manner are pre-evaluated and the values are passed directly into the program. The return value is collected from Tcl output. Performance is improved by eliminating time spent fetching data from the Runtime Program Environment (RPE) or putting data as output back into the RPE.

cestamp Selectable

CEStamp (Concurrent Engineering Stamp) implements optimistic offline lock, a method to prevent conflict between concurrent transactions by detecting a conflict and rolling back the transaction. When you have the cesstamp value, you can pass it to a program to validate a modification. See the ADK documentation for details.

.generic subselect

The kernel provides a number of APIs that output fields for dates, times, and real numbers according to global environment variables ( MX_NORMAL_DATETIME_FORMAT, MX_DECIMAL_SYMBOL, and so on) set by an Administrator. Since there are many formats possible to output these fields, a generic format can now be used to ensure consistent date, time, and real number format regardless of the global settings. To use the generic format, add the ‘generic’ subselect or suffix to a selectable, for example, attribute[Cost].generic or modified.generic.

The generic format for dates and times corresponds to JavaSimpleDateTimeFormat specified by the following date and time pattern: yyyy/MM/ dd'@'HH:mm:ss:z. For real numbers, the generic format returns a dot (.) as a decimal separator.

The ‘generic’ subselect can be added to almost any selectable which returns date/time or real numbers and can be used in both the Java APIs as well as the MQL APIs. It should not be used in where clauses or access filters.

print businessobject OBJECTID select modified.generic dump;