Example: Work log creation by using MBO APIs

The scripting framework does not have any functions to create a work log. You must use the documented MBO APIs to create the work log.

Many API invocations are used to create the work log. Because the script is running against the service request (SR) object, the scripting framework offers a handle to the service request object. The mbo keyword in the body of the script is used to retrieve the handle. Other related business objects can be accessed from the handle.
  • The first API called is the getMboSet method on the SR business object. The API is called with the code: worklogset = mbo.getMboSet ('WORKLOG'). The getMboSet method accepts a parameter that represents a relationship from the current SR business object to the WORKLOG business object. The parameter is a relationship name defined in the data dictionary. The method returns a handle to a set that represents a container for the related object.
  • The next API called is the add method. The API is called with the code: worklog = worklogset.add(). The add method returns a business object that can be initialized by setting values into the attributes of the object.
  • The next API called is the setValue method on the business object. The API is called with the code: worklog.setValue('clientviewable, 1'). The setValue method sets the value of the attribute on the business object.
  • Additional setValue methods are called to set the values of more attributes of the business object. The number of setValue invocations depends on the number of primary key and required attributes of the business object that is being created.

The data in the initialized business object is saved. You do not have to invoke a save method on the business object from within the script. The work log is now created if the volume of the pipeline is greater than 1000 cubic feet.