Work with Descriptive Flexfields and Scripting

Groovy scripting provides access to global descriptive flexfields and contextual descriptive flexfields. Global descriptive flexfields display on all change types while contextual descriptive flexfields only display on the change type to which they're assigned.

Work with Global Descriptive Flexfields

To work with global descriptive flexfields, use the ChangeObjectDFF accessor to access the collection of descriptive flexfields. In the descriptive flexfield collection, use the internal name of the attribute to get it and set it.

In the following example, the value of the global descriptive flexfield Implementation Reason is copied to the global descriptive flexfield PCN.

Let's look at the format for Object Functions and Field Triggers:
def changeDFF = ChangeObjectDFF 
def reason = changeDFF.implementationReason 
changeDFF.setAttribute('pcn', reason) 
Let's look at the format for Object Triggers:
def changeDFF = ChangeObjectDFF 
def reason = changeDFF.implementationReason 
if (reason != changeDFF.getAttribute('pcn'))
    { 
        changeDFF.setAttribute('pcn', reason)           
    } 

Work with Contextual Descriptive Flexfields

Use the ChangeObjectDFF accessor to access the descriptive flexfield collection like global descriptive flexfields. However, with contextual descriptive flexfields, assign the API name (all lower case) to a variable, and use the variable to get or set the attribute.

In the following example, the value of the global descriptive flexfield Implementation Reason is copied to the contextual descriptive flexfield Justification.

Let's look at the format for Object Functions and Field Triggers:
def apiName = 'justification'
def changeDFF = ChangeObjectDFF
def reason = changeDFF.implementationReason
changeDFF.setAttribute(apiName, reason)
Let's look at the format for Object Triggers:
def apiName = 'justification'
def changeDFF = ChangeObjectDFF
def reason = changeDFF.implementationReason
if(reason != changeDFF.getAttribute(apiName))
  {                
     changeDFF.setAttribute(apiName, reason)
  }

Work with Global Functions

Global functions enable you to:
  • Create reusable code that you can reference in other scripts.
  • Invoke a script from a product rule using InvokeGlobalFunction.

Since change orders are available in Application Composer, you can create triggers and validations for conditionally invoking scripts in most cases. However, invoking a script based on status change can only be accomplished through a global function being invoked by a product rule triggered as an entry or exit criteria.

Items aren't available in Application Composer. Therefore, you can only apply scripts to items as global functions that are invoked through a product rule.

Since global functions have no current object context, you must consider the following points while working with global functions:
  • You won't be able to use Groovy functions to perform operations in your script.
  • Global functions call REST web services to accomplish what’s needed.
  • To write global functions that work on a particular object, and call them from an object function, refer to Passing the Current Object to a Global Function.
  • To pass the current object context when invoking a global function from a product rule, create a parameter in the global function that receives the object ID from the rule.

    This image displays the Global Functions in Application Composer.

    This image shows the global function in Application Composer

    This image displays the validation condition that shows the global function

    This image shows the validation condition of the global function.

Groovy Script Examples

Application Composer supports Groovy scripting, which is a standard, dynamic scripting language for the Java platform. This section provides an example of how to use the setAttribute() function and the getAttribute() function with one or more lines of Groovy code.

Set an Attribute Value

To set the value of an attribute, use the setAttribute() function. The following example sets the Priority field to "High" on a change order using the PriorityCode attribute.
setAttribute("PriorityCode", "HIGH") 
To find the code names for the priority values, in the Setup and Maintenance work area, go to the following:
  • Offering: Product Management
  • Functional Area: Change Orders
  • Task: Manage Change Priorities

Get the Lookup Code for the value that you want to assign.

Get an Attribute Value

To get the value of an attribute, either use the getAttribute() function or just use the API name of the attribute.

Each of these scripts does the same thing, they return the value in the Priority field on a change order to Runtime Messages:
def getPriority = getAttribute("Priority") println(getPriority)
def priority = Priority println(priority)
println(Priority)

The command println() prints the value in the parenthesis to the Runtime Messages log in Application Composer in the Common Setup pane. To troubleshoot a script, it’s very important to enable Runtime Messages in Application Composer.

Let’s see how to enable Runtime Messages:
  1. In the Common Setup pane, select Runtime Messages.
  2. In the Application Script Log page, select the check box Enable My Application Script Logging.