Skip Headers

Agile Product Lifecycle Management Web Services Guide Release 9.3.3 E39310-01 |
| Contents

Previous | Next |

# 8 Working with Queries

A Query is a feature which helps you search for Agile PLM data. It defines a search similar to the searches in Agile Web Client. The search can have multiple search criteria (similar to the Advanced Search in Agile Web Client), or a simple search that specifies a single criterion.

## 8.1 Creating a Query

To create and execute a query, you must first create a Query object. As with other Agile API objects, you create the object using the createQuery operation.

In its simplest form, the parameters that you pass with the createQuery operation to create a query are the Query object type and the query class used in the search.

Example: Creating a Query

    CreateQueryRequestType createQueryRequestType =
    new CreateQueryRequestType();
    AgileCreateQueryRequestType[] agileCreateQueryRequestType =
        new AgileCreateQueryRequestType[1];
    agileCreateQueryRequestType[0] = new AgileCreateQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Personal Searches/Submitted Changes");
    QueryObjectType queryObjectType = new QueryObjectType();
    queryObjectType.setOwner("badriv");
    agileCreateQueryRequestType[0].setQueryParams(queryObjectType);
    createQueryRequestType.setRequests(agileCreateQueryRequestType);

The query class you specify with the createQuery operation also includes objects from all of its subclasses. For example, when you search for objects in the Item class, the results include Parts and Documents. When you search for objects in the Change class, the results include objects from all Change subclasses (Deviation, ECO, ECR, MCO, PCO, SCO, and Stop Ship). To search for a specific subclass, you must explicitly specify the class.

## 8.2 Creating a New Query from an Existing Query Object

You can also use the saveAsQuery operation to create a new query from an existing query object.

Example: Using IQuery.saveAs() to save a query to a folder

    SaveAsQueryRequestType saveAsQueryRequestType =
    new SaveAsQueryRequestType();
    AgileSaveAsQueryRequestType[] agileSaveAsQueryRequestType =
        new AgileSaveAsQueryRequestType[1];
    agileSaveAsQueryRequestType[0] = new AgileSaveAsQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Personal Searches/Submitted Changes");
    agileSaveAsQueryRequestType[0].setQueryIdentifier(queryObjectIdentifierType);
    agileSaveAsQueryRequestType[0].setNewQueryIdentifier("Personal Searches/My Submitted Changes");
    saveAsQueryRequestType.setRequests(agileSaveAsQueryRequestType);

## 8.3 Loading a Query

This is used to load a query.

Example: Loading a query

    LoadQueryRequestType loadQueryRequestType =
    new LoadQueryRequestType();
    AgileLoadQueryRequestType[] agileLoadQueryRequestType =
        new AgileLoadQueryRequestType[1];
    agileLoadQueryRequestType[0] = new AgileLoadQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Recycle Bin Searches/Deleted Changes");
    agileLoadQueryRequestType[0].setQueryIdentifier(queryObjectIdentifierType);
    loadQueryRequestType.setRequests(agileLoadQueryRequestType);

## 8.4 Executing a Saved Query

This is used to execute a saved query existing in the system.

Example: Executing an existing Query saved in the Agile system

    ExecuteSavedQueryRequestType executeSavedQueryRequestType =
    new ExecuteSavedQueryRequestType();
    AgileExecuteSavedQueryRequestType[] agileExecuteSavedQueryRequestType =
        new AgileExecuteSavedQueryRequestType[1];
    agileExecuteSavedQueryRequestType[0] = new AgileExecuteSavedQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Recycle Bin Searches/Deleted Changes");
    agileExecuteSavedQueryRequestType[0].setQueryIdentifier(queryObjectIdentifierType);
    executeSavedQueryRequestType.setRequests(agileExecuteSavedQueryRequestType);

## 8.5 Updating a Saved Query

This is used to update an existing query.

Example: Updating an existing query

    UpdateQueryRequestType updateQueryRequestType =
    new UpdateQueryRequestType();
    AgileUpdateQueryRequestType[] agileUpdateQueryRequestType =
        new AgileUpdateQueryRequestType[1];
    agileUpdateQueryRequestType[0] = new AgileUpdateQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Personal Searches/Submitted Changes");
    agileUpdateQueryRequestType[0].setQueryIdentifier(queryObjectIdentifierType);
    QueryObjectType queryObjectType = new QueryObjectType();
    queryObjectType.setOwner("badriv");
    agileUpdateQueryRequestType[0].setNewQueryParams(queryObjectType);
    updateQueryRequestType.setRequests(agileUpdateQueryRequestType);

## 8.6 Deleting a Query

To delete a query that has been saved, use the deleteQuery operation.

Queries which are created but not saved to a folder after the user session is closed are temporary queries. Make sure you delete the temporary queries, especially after you run lengthy sessions.

Example: Deleting a query

    DeleteQueryRequestType deleteQueryRequestType =
    new DeleteQueryRequestType();
    AgileDeleteQueryRequestType[] agileDeleteQueryRequestType =
        new AgileDeleteQueryRequestType[1];
    agileDeleteQueryRequestType[0] = new AgileDeleteQueryRequestType();
    QueryObjectIdentifierType queryObjectIdentifierType = new QueryObjectIdentifierType();
    queryObjectIdentifierType.setName("Personal Searches/MySubmittedChanges");
    agileDeleteQueryRequestType[0].setQueryIdentifier(queryObjectIdentifierType);
    deleteQueryRequestType.setRequests(agileDeleteQueryRequestType);