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.
def changeDFF = ChangeObjectDFF
def reason = changeDFF.implementationReason
changeDFF.setAttribute('pcn', reason)
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.
def apiName = 'justification'
def changeDFF = ChangeObjectDFF
def reason = changeDFF.implementationReason
changeDFF.setAttribute(apiName, reason)
def apiName = 'justification'
def changeDFF = ChangeObjectDFF
def reason = changeDFF.implementationReason
if(reason != changeDFF.getAttribute(apiName))
{
changeDFF.setAttribute(apiName, reason)
}
Work with Global Functions
- 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.
- 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 displays the validation condition that shows 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
setAttribute("PriorityCode", "HIGH")
- 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.
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:- In the Common Setup pane, select Runtime Messages.
- In the Application Script Log page, select the check box Enable My Application Script Logging.