Home > DOCUMENTUM > How and When to Use Save() method in TBO ?

How and When to Use Save() method in TBO ?

May 10, 2010

The save method can be used in TBO class to extend the default behavior and provide own custom implementation for validations and so on.

Generally , Creating a document in WebTop involves 3 steps: filling the ‘Create’ tab, ‘info’ tab, and ‘Permissions’ tab. User has to click on Next and Finish buttons to complete the activity of creating document. Also user has the option to select a document template in the ‘Create’ tab. This selection of template and clicking of buttons Next and Finish needs to be captured.

Consider a case in which a new document is created in WebTop and based on attributes entered in the document metadata (fields in ‘Info’ tab) a folder structure needs to be created.

save() method can be overridden in the TBO class for different scenarios: When document is created in WebTop using a template and when not using a template.

CASE 1 : When a template is used for creating document in WebTop, before the Finish button is
clicked,

1) The version label attribute (r_version_lablel) of the document object is always updated as ‘1.0, Current, _NEW_’.

2) Also, save() method in the TBO class is called twice, once when NEXT button is clicked on ‘Create’ tab and second time when Finish button is clicked.

CASE 2 : When no template is used for creating document (for example: creating documents without
any content)

1) The version label is always 1.0, Current.

2) The save() method is called only once, when NEXT button is clicked in ‘Create’ tab. When Finish button is clicked, the method called is saveLock().

While using TBO for custom object type, we can use a dummy attribute and r_version_label attributes to keep track of which button is clicked in the above two scenarios. The reason for this kind of check is the folder structures should get created only when Finish button is clicked. Otherwise the folder structure created needs to be deleted if the user clicks on Cancel button while creating document.

Below if the Code Snippet illustrating the same:

public void save() throws DfException {
IDfSession session = null ;
IDfPersistentObject docObject = null ;
try{
session = getSession() ;
docObject = session.getObject(getObjectId()) ;
}catch( Exception e ) {

// failed to create

if( e instanceof DfException )
throw (DfException)e;
throw new DfException( DfException.DM_NOTDFC_E_JAVA,
e.toString() );
}

// THE ATTRIBUTE ‘subject’ CAN BE A DUMMY ATTRIBUTE

if(docObject.getString(“subject”).equals(“”)){
docObject.setString(“subject” ,”false”) ;
}
super.save();
try{
docObject = session.getObject(getObjectId()) ;

// RETRIEVING THE VALUES OF THE ATTRIBUTE ‘r_version_label’

String str =
docObject.getAllRepeatingStrings(“r_version_label”,”,”) ;
if(str.indexOf(“_NEW_”) > 0 ){

// WITH TEMPLATE

docObject.setString(“subject”,”true”) ;
super.save();
}else{
if(docObject.getString(“subject”).equals(“true”)){

// WITH TEMPLATE, FINISH button

docObject.setString(“subject”,”false”) ;

// can create folders

}
}
}catch( Exception e ) {

// failed to create

System.out.println(“exception :”+e.toString());
if( e instanceof DfException )
throw (DfException)e;
throw new DfException( DfException.DM_NOTDFC_E_JAVA,
e.toString() );
}
}
}

In my next post i will try to discuss how to use the savelock() and checkInEx(…) methods.

%d bloggers like this: