# Oracle Agile PLM SDK Java Snippet Generator: Items and BOM

> Source: https://netray.co/tools/agile-plm-sdk-java-snippet-generator
> Publisher: Netray (netray.co), AI and integration engineering for ERP and manufacturing systems.
> Section: Free Tools

## Short answer

Fill in the Agile URL, user and item number to get compilable Java that logs in with AgileSessionFactory, reads an item description and walks its BOM, plus a Process Extension custom action.

## Category

developer

## Erp

Oracle Agile PLM

## Audience

- Agile PLM developer
- PLM administrator
- Integration developer

## Tool

**Kind:** template

**Output:** code

**Language:** java

**Fields:**

#### Agile server URL

**Key:** url

**Type:** text

**Default:** http://agile.example.com:7001/Agile

#### Integration user

**Key:** username

**Type:** text

**Default:** integration_user

#### Item number

**Key:** item_number

**Type:** text

**Default:** 1000-0123

#### Java class name

**Key:** class_name

**Type:** text

**Default:** ReadItemBom

#### Process Extension class name

**Key:** px_class

**Type:** text

**Default:** BomLineCountAction

**Blocks:**

#### Standalone SDK client ({{class_name}}.java)

**Body:** import com.agile.api.APIException;
import com.agile.api.AgileSessionFactory;
import com.agile.api.IAgileSession;
import com.agile.api.IItem;
import com.agile.api.IRow;
import com.agile.api.ITable;
import com.agile.api.ItemConstants;

import java.util.HashMap;
import java.util.Iterator;

public class {{class_name}} {

    public static void main(String[] args) {
        IAgileSession session = null;
        try {
            HashMap<Object, Object> params = new HashMap<Object, Object>();
            params.put(AgileSessionFactory.USERNAME, "{{username}}");
            params.put(AgileSessionFactory.PASSWORD, System.getenv("AGILE_PASSWORD"));

            AgileSessionFactory factory = AgileSessionFactory.getInstance("{{url}}");
            session = factory.createSession(params);

            IItem item = (IItem) session.getObject(IItem.OBJECT_TYPE, "{{item_number}}");
            if (item == null) {
                System.out.println("Item {{item_number}} not found");
                return;
            }

            Object desc = item.getValue(ItemConstants.ATT_TITLE_BLOCK_DESCRIPTION);
            System.out.println("{{item_number}}: " + desc);

            ITable bom = item.getTable(ItemConstants.TABLE_BOM);
            System.out.println("BOM lines: " + bom.size());
            Iterator<?> it = bom.iterator();
            while (it.hasNext()) {
                IRow row = (IRow) it.next();
                Object child = row.getValue(ItemConstants.ATT_BOM_ITEM_NUMBER);
                Object qty = row.getValue(ItemConstants.ATT_BOM_QTY);
                System.out.println("  " + child + "  qty " + qty);
            }
        } catch (APIException e) {
            System.err.println("Agile API error: " + e.getMessage());
        } finally {
            if (session != null) {
                session.close();
            }
        }
    }
}

#### Process Extension custom action ({{px_class}}.java)

**Body:** import com.agile.api.APIException;
import com.agile.api.IAgileSession;
import com.agile.api.IDataObject;
import com.agile.api.IItem;
import com.agile.api.INode;
import com.agile.api.ITable;
import com.agile.api.ItemConstants;
import com.agile.px.ActionResult;
import com.agile.px.ICustomAction;

public class {{px_class}} implements ICustomAction {

    public ActionResult doAction(IAgileSession session, INode actionNode, IDataObject affectedObject) {
        try {
            IItem item = (IItem) affectedObject;
            ITable bom = item.getTable(ItemConstants.TABLE_BOM);
            return new ActionResult(ActionResult.STRING, "BOM lines: " + bom.size());
        } catch (APIException e) {
            return new ActionResult(ActionResult.EXCEPTION, e);
        }
    }
}

#### Compile and run

**Body:** javac -cp AgileAPI.jar {{class_name}}.java
java -cp AgileAPI.jar:. {{class_name}}

(On Windows use ; instead of : in the classpath. Take AgileAPI.jar from the same Agile server release and patch level.)

**Notes:** Class, method and constant names follow the Agile PLM SDK Developer Guide and API reference (com.agile.api and com.agile.px): AgileSessionFactory.getInstance, createSession, USERNAME and PASSWORD, IItem.OBJECT_TYPE, ItemConstants.ATT_TITLE_BLOCK_DESCRIPTION, TABLE_BOM, ATT_BOM_ITEM_NUMBER, ATT_BOM_QTY, ICustomAction.doAction and ActionResult. The BOM table returned is for the item's current (latest released) revision unless you set a revision first. Verify the URL form and JDK level against your 9.3.x release notes.

## Content

**Intro:** This generator writes Java against the Oracle Agile PLM SDK (com.agile.api) that logs in, loads an item, reads its title block description and iterates its BOM table, plus a Process Extension custom action skeleton. It targets Agile PLM 9.3.x, including 9.3.6.

**Sections:**

#### How to use it

**Body:** Enter your Agile application URL (the same base the Java client uses, typically http://host:port/Agile), an integration user and an item number. Put AgileAPI.jar from your server's SDK folder on the classpath, set the AGILE_PASSWORD environment variable and run. The program prints the description, the BOM line count and each child item number with its quantity. The second block is a Process Extension: once deployed and configured as a custom action, a user can run it from the Actions menu on an item and see the BOM line count.

**Bullets:**

- Always close the session in finally; leaked sessions count against server limits.
- Use an integration user with read privileges on the items you query.
- Match the AgileAPI.jar version to the server, including patch level.

#### How the SDK object model works

**Body:** AgileSessionFactory.getInstance(url) returns a factory for one server, and createSession takes a map of USERNAME and PASSWORD. session.getObject(IItem.OBJECT_TYPE, number) returns the item or null. Values on the main page (title block, page two, page three) are read with getValue and an attribute constant such as ItemConstants.ATT_TITLE_BLOCK_DESCRIPTION. Tabs are tables: item.getTable(ItemConstants.TABLE_BOM) returns an ITable whose rows are IRow objects, and each cell is read with row.getValue and a BOM attribute constant. Custom attributes are read by their API name or attribute ID, which you find in Java client Admin under the class attributes.

#### Standalone client versus Process Extension

**Body:** A standalone client runs outside Agile, opens its own session and suits integrations, nightly extracts or ERP interfaces. A Process Extension runs inside the Agile application server: Agile passes in an already authenticated session, the node that triggered it and the affected object, so you never handle passwords. Custom actions implement ICustomAction and return an ActionResult; event-driven logic uses the event framework interfaces instead. PX classes are packaged as a jar, deployed to the server's SDK extensions folder (integration/sdk/extensions under the Agile home in a default install) and registered in Java client Admin under Process Extensions.

#### Gotchas

**Body:** After an Agile upgrade, recompile every PX and SDK client against the new AgileAPI.jar; mismatched jars cause odd runtime errors. Reading a BOM returns rows for the current revision, so pending changes may not appear unless you set the revision on the item first. Iterating very large BOMs one row at a time is slow over the network; for bulk extracts, use queries or the Agile Integration Services where available. Run integrations as a dedicated user and audit what it can see; the SDK enforces the same privileges as the UI.

**Cta:** If you want engineers to ask Agile PLM about items, BOMs and changes in plain English on your own servers, we can build that on top of these same SDK calls.

**Faq:**

#### How do I connect to Oracle Agile PLM from Java?

**Answer:** Add AgileAPI.jar to the classpath, create a HashMap with AgileSessionFactory.USERNAME and PASSWORD, call AgileSessionFactory.getInstance(url) and then factory.createSession(params). The URL is the Agile application URL, for example http://host:7001/Agile. Close the session when done.

#### How do I read a BOM with the Agile PLM SDK?

**Answer:** Load the item with session.getObject(IItem.OBJECT_TYPE, number), call item.getTable(ItemConstants.TABLE_BOM), iterate the table and cast each element to IRow. Read child number and quantity with row.getValue(ItemConstants.ATT_BOM_ITEM_NUMBER) and ATT_BOM_QTY. For a full multi-level BOM, recurse into each child item.

#### What is a Process Extension (PX) in Agile PLM?

**Answer:** A Process Extension is custom Java code that runs inside the Agile server. Custom actions implement ICustomAction and can be triggered from the Actions menu, workflow or other PX hooks. They receive an authenticated session and the affected object, so no credentials are stored. They are deployed as a jar and registered in Java client Admin.

#### Where is the Agile PLM SDK Developer Guide?

**Answer:** It is part of the Oracle Agile PLM documentation library for each release, published on Oracle's documentation site alongside the API reference Javadoc. Use the guide that matches your release (for example 9.3.6), since constants and supported features change between versions.

## Search terms

oracle agile plm java api, oracle agile plm api, agile plm sdk guide, agile plm sdk example, agile sdk read bom, agile plm process extension example, agilesessionfactory createsession

---
Talk to an engineer: https://netray.co/contact?intent=erp_ai | Machine catalog: https://netray.co/agent/catalog.json
