Application Composer Series: Using Groovy To Manipulate Objects

This post discusses the main process for building Groovy code into your Application Composer customizations so you can dynamically manipulate Business Object data like Opportunities or Partners at run-time. 

Use Cases

We discuss two main common use-cases in this article are; (1) getting data from another business object record, and (2) creating new business object records. Within this we'll explain the process involved and look at some simple code snippets. The examples here can be used wherever there is the option to add Groovy logic to your customization, such as in Actions and Links, Triggers, Object and Global Functions, and Object Workflows.

Querying Objects Records

Since Groovy uses ADFbc View Objects for accessing the underlying applications data, the first question is usually 'what View Objects are available for use'? Since these are internal code artifacts this might not be obvious, however the information is exposed by Application Composer through the newView() function pop-up from the Expression Palette, as illustrated below. In addition when adding code under Standard Objects all the attributes are listed in the Fields tab in the Expression Palette.

View Object list (click here for a larger image)

To query object records that already exist, you can use the FindByKey() method which accepts a key object (usually a primary key) and the maximum number of rows you want (normally one). It returns an array of the row(s) that match. We'll cover how to define your key object in our next article in this series, so for now here is a simple example that uses the ID field of the custom object:

def vo = newView('MyCustomObject_c')
def myResult = vo.findByKey(100000000001234,1)

After this you can then use the size() function to check the number of rows returned and the hasNext() method to loop through in case of more than one match, followed by the next() method for accessing its fields and values. As mentioned, future Application Composer Series articles with cover examples of this, including recommendations on the filtering of returned object records, including the use of a ViewCriteria.

Querying Child and Related Objects

If your parent object has logic that must include field values from its children, then you do not need to instantiate the children in code, since they're available already through the 'Related Collection' feature. This allows you to simply iterate through the one-or-more of the child objects and use the fields as required. The following example illustrates this, returning the list of child contact names associated with the parent opportunity into to a custom field.

partyString "Related Contacts Are: " 
def myContacts OpportunityContact
while (myContacts.hasNext()) {
  def oneContact
  partyString +=" ${oneContact.PartyName}\n"
setAttribute("OptyChildContactNames_c", partyString)

Inserting new Object Records

As discussed in other Application Composer posts, to create new records outside of the UI you can use the import features or (Release 7 onwards) call the related web services. For building in dynamic logic as part of your customization however, it is recommended to use Groovy and the insertRow() method that exists in the View Object class. The following simple example illustrates this, where a new appointment object is created when a custom Opportunity Field (Next Contact Date) is modified to trigger the code. No explicit commit is needed since it is included in the underlying AM transaction.

if (isAttributeChanged(‘NextContactDate_c’))
def voAppointment = newView(‘AppointmentVO’)
def createAppt = voAppointment.createRow()
def currentDateTime = now()
def apptName = ‘Auto Appointment’ + currentDateTime
createAppt.setAttribute(‘ActivityName’, apptName)
createAppt.setAttribute(‘SourceObjectId’,OptyId )

In addition, the following short video shows the same kind of example, but instead adding Groovy code to an action button for creating a new custom object record (for storing additional data) directly from the Opportunities page. Whilst it might be more sensible to use a Field or Object Trigger for this purpose, the button-press illustrates the moving parts more clearly for demonstration.


Whilst Application Composer is founded from Oracle ADF, care should be taken in using content that is not specific to the Application Composer implementation since only selected methods and features are implemented.

  • Oracle CRM / Sales Cloud Groovy Scripting Reference Guide
  • Our own Introduction To Groovy Whitepaper
  • JDeveloper ADF generic Introduction To Groovy document

How to copy row in revenue item to another custom object?

Posted by guest on July 15, 2014 at 12:52 AM PDT #

I am not 100% clear on your requirement, however if you wish to assign fields in a custom object the data that exists in the application (e.g. revenue item) then I would recommend you first assign the value to a variable then use the simple setAttribute() method on your custom object. Unfortunately there is no shortcut way of copying entire records between objects.

See more examples in our whitepaper ( or the documentation (

Posted by Richard Bingham on July 16, 2014 at 03:23 AM PDT #

Can setAttribute() be used to set the value of the 'Name' field in an Opportunity? The trigger I have written works when changing another text field, but not the 'Name' field.

Posted by guest on January 08, 2015 at 09:12 AM PST #

I tested to check and setAttribute('Name',"NewDesc") works for me.
Can you verify the trigger definition you are using and your groovy. If you could consider using our forum, you can post screenshots and get input from our community also.

Posted by Richard Bingham on January 08, 2015 at 10:10 AM PST #

can any one help me. I have to create the account in crm on demand from oracle sales cloud. means whenever we create account or any object record it should reflect in crm on demand.

Posted by guest on January 12, 2015 at 10:41 PM PST #

So whilst you could use a Object Trigger or an Object Workflow in Sales Cloud to make the creation call, you'll need to understand the API/options for creating records in CRM OnDemand.
We're not CRM OnDemand experts, but did a quick search and found the document below which details the web services available in CRM OnDemand and from a scan it seems to include an insert operation (AccountInsert) for the Account object (page 291).
Hope this helps.

Posted by Richard Bingham on January 13, 2015 at 11:23 AM PST #

Can anyone help me how to call the webservice through groovy code in sales cloud . we need to call the wsdl file of CRMOD through web service in sales cloud.

Posted by guest on January 13, 2015 at 09:39 PM PST #

First you need to register the web service in Application Composer, then once registered you can call it in your Groovy code using the adf.webservices prefix (or select via the Palette) and pass in your map payload.

See the following for more detail:

If you have further questions, please consider using our forum where the whole community can input and benefit from the discussion.

Kind regards

Posted by Richard Bingham on January 14, 2015 at 05:50 AM PST #

Another video example of calling a webservice in groovy (an internal service in this case, but thats not especially important), can be found here:
Kind regards

Posted by Richard Bingham on January 15, 2015 at 03:58 AM PST #

I am not able to register the CRMOD web services in oracle sales cloud. there for we can not save the web service in sales cloud.

i am downloading the wsdl file from CRMOD
admin>web service administration(in Integration option)>web service v2.0>account-----download generic wsdl
and the taking the url of that wsdl

Posted by guest on January 15, 2015 at 10:57 PM PST #

Please could you post a screenshot/navigation of your problem registering your CRMOD web services in sales cloud to our forum where we can look at this in more detail and follow up as needed.

Posted by Richard Bingham on January 16, 2015 at 05:00 AM PST #

How to populate One Object(Account) fixedchoiceList value into another Objects(Opportunity)FIxedChoiceList.

Posted by guest on January 20, 2015 at 10:35 PM PST #

Can any one help me, How to get all the sales accounts which are modified after a certain date.

Posted by guest on February 05, 2015 at 03:26 AM PST #

For the question above regarding populating one LOV from another:

1. For interacting with LOVs the new functions getSelectedListDisplayValue() for single value fixed lists, and getSelectedListDisplayValues() for multi-select lists. Create a list object with these values, then iterate and use each one. There is an example here:
Populating an existing LOV with data at runtime using groovy code is not possible. Take a look at "depends on" functionality - maybe you can use this for your purpose however. See

Posted by Richard Bingham on February 10, 2015 at 02:00 AM PST #

I am not sure how you wish to display the Sales Account records by date, but you can query them in Groovy using the setSortBy() function of the View Object instance you create from the newView(). This is detailed (with example) here:
Hope this helps,

Posted by Richard Bingham on February 10, 2015 at 02:07 AM PST #

In reference to "Querying Child and Related Objects", where does "OpportunityContact" come from in "def myContacts OpportunityContact"? I am using a custom object called License which is related to Contacts via a field (one contact to many licenses). I try "ContactLicense" and it does not work. I have also tried "PersonProfileLicese" with no success. The code snippet you are using for the example is almost exactly what I need to do, I just keep getting the error that "ContactLicense was not recognized".

Posted by dsimer on April 01, 2015 at 08:28 AM PDT #

Hi DSimer,
The "OpportunityContact" is the API name of the related (child) object. If your child is called License then its API is probably License_c or something like that. Just click the object name and see the API name field.
Kind regards

Posted by Richard Bingham on April 07, 2015 at 12:28 AM PDT #

Post a Comment:
  • HTML Syntax: NOT allowed

Follow us on twitter Fusion Applications Extensibility, Customizations and Integration forum Fusion Applications Dev Relations YouTube Channel
This blog offers news, tips and information for developers building extensions, customizations and integrations for Oracle Fusion Applications.


« April 2015