Thursday, March 22, 2007

How do I determine the default value for an attribute of a type from the data dictionary?

1. Current "official" way is to run a query:

select r_object_id, attr_name, default_value from dmi_dd_attr_info where type_name = '' and business_policy_id = '0000000000000000' and nls_key = ''

or for a specific attribute:

select r_object_id, attr_name, default_value from dmi_dd_attr_info where type_name = '' and attr_name = ' and business_policy_id = '0000000000000000' and nls_key = ''

default_value returned from the query is an object ID pointing to an expression object, and from there, you can get the value of the expression_text.

For an example, check out ypli_type081502 type with attribute attr1 in qa_client2 docbase. . You'll see that the default_value returned is 53016e8d80003913. Dumping this ID will show you the structure of this object, including "expression_text". You probably can optimize by putting the two steps into one query.

2. Another method is to get to it through IDfSession.getTypeDescription.
This method is ok if you are not getting the default value info for a lot of attributes, or performance is not a main concern for the customer. One getTypeDescription call can add about 0.5 second of overhead.

IDfTypedObject tobj = IDfSession.getTypeDescription (, null, null); // just put null for policy and state parameters

// loop to get all default values (it is a repeating attribute)
{
IDfId defValueId = tobj.getRepeatingId ("default_value");
IDfPersistentObject pobj = session.getObject(defValueId);
String defaultValue = pobj.getString ("expression_text");
... // manipulate the default value
}

3. The quick and dirty way is:
create an object of that type (don't save), and retrieve the attribute value.
This is not a good idea for production code. Just ok for ad-hoc testing.

No comments: