View Objects in Scripts

A view object is an Oracle ADF component that simplifies querying and working with business object rows. You access view objects when you write Groovy scripts using the expression builder in Application Composer.

To access view objects in your scripts, use the newView() function for an object API name. The newView() function accesses a custom or standard view object, and creates a new view object instance that programmatically accesses that business object's rows. For example, a common task that you will do with this new view object instance is to query some data. Do this by calling the findByKey() function on the view object to find a row by key.

For more information on accessing view objects, see "Accessing the View Object for Programmatic Access to Business Objects" in the Groovy Scripting Reference guide.

This topic:

  • Explains why the newView() function is useful in your scripts.

  • Explains how to access view objects, either custom or standard, from the expression builder using the newView() function.

  • Provides a list of the standard view objects that are provided in Application Composer.

newView() Function

When you write Groovy scripts in Application Composer, you're usually in the context of a specific record from a specific object. For example, you can write a trigger script with a single line "setAttribute('Name','Acme Widgets Inc.')" and the script will be executed on the user's current record.

The newView() function, by contrast, lets you construct a new reference to an object which doesn't require any contextual relationship to the current record. For example, the line "def myVO = newView('OpportunityVO')" produces an instance of the Opportunity view object that your script can query and read, and then add, delete, or update rows.

Accessing View Objects

To access view objects, use the newView() function for an object API name from within the expression builder in Application Composer:

  1. Navigate to the expression builder from Application Composer.

    There are several ways to start the expression builder in Application Composer. For example, start the expression builder when editing a field to make it required.

  2. In the expression builder palette, on the Functions tab, select the Other category and the newView() function.

  3. Click Insert.

    A window displays that lists the view objects you can call in your script.

    The objects don't have to be related to the current object to appear in this list.

Examples of Standard View Objects

The standard objects that are delivered with your application provide view objects for use in your scripts. The previous section described how to access those view objects. This section provides some examples of standard view objects that are provided in Application Composer, and how you might use them in your scripts. Attributes that you would typically script against are also included.

For objects that aren't extensible and thus not available in Application Composer, see the SOAP Web Services documentation for your cloud service to view a list of attributes that you can script against.

Standard View Object

Description

Typical Attributes

Address

Use this object to access the address for a given party in scripting, if the current object doesn't have a view link to the Address object.

Access this Address extensible object as a child of the Account, Contact, or Household objects.

Refer to the Address object in Application Composer, and review the descriptions provided for all attributes.

CodeAssignment

Use this object to access classifications assigned to a given party in scripting, if the current object doesn't have a view link to this object.

Access this object as a child of the Account or Contact objects.

Refer to the Trading Community Classification Code Assignment in the SOAP Web Services documentation for your cloud service.

CommonLookup

Access application common lookups in scripting.

LookupType, LookupCode, Tag, EnabledFlag, StartDateActive, EndDateActive, Meaning, Description

Contact

Use this object to access customer contact information in scripting, if the current object doesn't have a view link to this object.

Access this Customer Contact Profile extensible object as a child of the Account, Contact, or Household objects.

Refer to the Customer Contact Profile object in Application Composer, and review the descriptions provided for all attributes.

FndTreeVersion

Use this object in scripting to access tree versions.

The customer hierarchy and party hierarchy are modeled as trees.

TreeStructureCode, TreeCode, TreeVersionID, Status, EffectiveStartDate, EffectiveEndDate, TreeVersionName

FndTreeNode

Use this object to determine the parent/child relationships for a given hierarchy.

The hierarchy for a given version is stored in this object.

TreeStructureCode, TreeCode, TreeVersionID, TreeNodeID, ParentTreeNodeID, Depth, ChildCount, ParentPk1Value

FndTreeNodeRf

Use this object in scripting to easily access the flattened version of the given hierarchy version.

TreeStructureCode, TreeCode, TreeVersionID, TreeNodeID, Pk1Value, AncestorPk1Value, Distance, IsLeaf

Location

Use this object to update or create physical location fields.

Address is the intersection of location and party. Address fields like city, state, and country are stored in the location. These fields are made available in the Address object for read-only purposes. Use this object if you need write access to location fields in scripting.

Refer to the Trading Community Location SDO in the SOAP Web Services documentation for your cloud service.

OrganizationParty

Use this object to get the organization party and all of its children when you have the organization PartyID in your script, and you don't have a view link from the current object to the Account object.

Refer to the Trading Community Organization Details in the SOAP Web Services documentation for your cloud service.

OrganizationProfile

Access this Account extensible object as a child of an OrganizationParty row or directly get the profile if you have a PartyID.

Refer to the Account object in Application Composer, and review the descriptions provided for all attributes.

OriginalSystemReference

Use this object to get the ID for given TCA object based on the source system and source system reference information.

Refer to the Trading Community Original System Reference in the SOAP Web Services documentation for your cloud service.

PersonParty

Use this object to get the Person Party and all of its children when you have the person PartyID in your script, and you don't have a view link from the current object to Account object.

Refer to the Trading Community Person Details in the SOAP Web Services documentation for your cloud service.

PersonProfile

Access this Contact extensible object as a child of a PersonParty row or directly get the profile if you have a PartyID.

Refer to the Contact object in Application Composer, and review the descriptions provided for all attributes.

Relationship

Use this object in scripting if you have a RelationshipID on the current object and that object doesn't have a view link to this object.

Access this Relationship extensible object as a child of the Account, Contact, or Household objects.

Refer to the Relationship object in Application Composer, and review the descriptions provided for all attributes.

Resource

Use this Resource extensible object in scripting to get the resource object details if you have a user or resource PartyID, and the current object ID doesn't expose a view link to this object.

Refer to the Trading Community Resource Profile in the SOAP Web Services documentation for your cloud service.

Example of Retrieving the Resource PartyID

In this example, you populate a custom dynamic choice list field that points to the Resource object. The dynamic choice list field displays on the Notes details page.

On the Note object, create either an After Create or Before Insert trigger, depending on your requirements:

def partyID = oracle.apps.cdm.foundation.publicModel.common.util.HzSessionUtil.getUserPartyId()
def view_Resource = newView('Resource')
def view_Criteria = newViewCriteria(view_Resource)
def view_criteria_row = view_Criteria.createRow()
def view_condition = view_criteria_row.ensureCriteriaItem('PartyId')
view_condition.setOperator('=')
view_condition.setValue(partyID)
view_Criteria.insertRow(view_criteria_row)
view_Resource.appendViewCriteria(view_Criteria)
view_Resource.setMaxFetchSize(1)
view_Resource.executeQuery()

// Once found get access to the record attributes
def var_record = view_Resource.first()
// Printing the Resource Party Id in Runtime messages
println ("The value for Resource Party Id is "+ var_record.ResourceProfileId)