|
<< Click to Display Table of Contents >> Navigation: Fundamental Operations > The Integrated Advanced Filter |
Introduction
Applying common filters
Applying custom filters
Advanced Filter logical groups
Searching within projects and assemblies
Displaying query results
Saving and loading queries
Incremental conditions: cascading value lists
Managing linked and special fields
Full text search in Advanced Filter
In MechworksPDM a general attempt has been made to centralize and simplify the user interface. The Advanced Filter, which was running in a separate window and used to offer a limited set of commands has been rewritten in its interface to provide a more natural look and feel and run integrated inside the Tree Page of the MechworksPDM browser. The results are displayed directly inside the browser, offering the full sets of commands on each record and allowing batch operations.

Most common filters have been made available in drop down lists. These queries involve the type of document you are looking for and the state. Searches by ID have been deliberately left out as the quick search integrated in the browser is more effective for this type of queries.

Models, as recalled by the icons, includes in the search parts and assemblies. All other documents includes in the search all the non cad documents. Following this entry in the list are added all file types that are not cad documents. In the image below, the last entry displays DWG documents that on the workstation are opened by default using the eDrawing application. All types of non cad documents available in the database are added to the list:

To sum up: the list of other documents depends on the files registered in the database while the icon depends on the current settings on the workstation and reflects the settings of Windows Explorer.
The second list allows you to filter the record by state

a special entry has been added to quickly find the documents you have checked out and are therefore locked by you for editing. Since other users have no write acces to these files a periodic check is adviced not to lock files for longer than necessary.
You can apply custom filters on any of the fields defined for documents. Custom conditions are enlisted at the bottom of the interface

To add a new condition, click the button Add condition. A new line appears below with three drop down lists.
The first list includes the field names. The first field, anywhere, indicates that the query is ran on all text fields. The second list displays all the conditions such as 'contains' or 'smaller than' and depends on the type of field selected in the first list. Changing the condition may change the number of lists: the condition 'is not null' does not need any parameter, so the third list is removed and first two enlarged to exploit the horizontal space as much as possible. The third list includes the distinct values in the database available for the field selected in the first list. The list is filled only if there are less than 500 distinct values for performance reasons.

In the image the file directories available in the database are enlisted in alphabetical order.
Single conditions can be temporarily disabled or removed.
To disable just disable the checkbox: ![]()
To remove them, click the red button beside the condition ![]()
By default, custom conditions are joined by AND, so all conditions must match. Click an operator between the rows to change it. For nested combinations, see Advanced Filter logical groups below.

The field anywhere is a special field and indicates a multiple fields search. Anywhere applies always only to fields of type text, so it isn't valid for dates or numbers. More, if in the options User Interface, Browser Behavior, Limit full text search... a list of fields is defined to simplify these queries then the query applies only to those fields.
Custom conditions can be combined with nested AND and OR groups to build expressions such as (A OR B) AND C without writing SQL manually. AND requires both branches to match; OR requires at least one branch to match. Each branch can be a single condition or a group of conditions.

The schematic compares the same three conditions with two different groupings. Group lower rows changes (A OR B) AND C into A OR (B AND C); Group upper rows reverses the change. GEARBOX is an example assembly ID.
How the layout works
Each row remains a normal Advanced Filter condition. The indentation shows which conditions belong together. For example:
APPROVAL_DATE [is not null]
OR
ID [contains] [0010]
AND
CHECK_OUT_BY [is exactly] [Giorgio]
Here, the two more deeply indented conditions form an AND group. That group is combined with the first condition using OR. The equivalent expression is:
APPROVAL_DATE is not null OR (ID contains 0010 AND CHECK_OUT_BY is exactly Giorgio)
A document therefore matches if its approval date is present, or if both its ID contains 0010 and its checked-out-by value is Giorgio. The grouping shown by the indentation becomes logical parentheses in the query and determines how the conditions are combined.
Changing an operator
Click an AND or OR label between the rows to open its menu. Choose And to require both branches, or Or to accept either branch. Only the selected group changes; operators within other groups keep their current settings.
Changing the grouping
The same menu includes Group lower rows and Group upper rows. These commands move the grouping toward the rows below or above the selected operator. A command is available only when the current structure permits that change.
For example, Group lower rows can change (A OR B) AND C into A OR (B AND C); Group upper rows reverses that grouping. The commands change the logical parentheses and can therefore change the search results. They do not change the individual condition values. Check the updated indentation after changing a group.
Existing filters
Previously saved filters remain compatible. If a filter has no saved nested groups, it is loaded using its original single operator across all conditions, preserving its previous behavior.
Grouping also determines which constraints apply to each value dropdown. See Incremental conditions: cascading value lists for examples and the exceptions for assembly and project selectors.
The parameter file schema\AdvFilterFields.txt regulates the list of fields that can be dropped down in custom conditions in the integrated Advanced Filter.
The file is a list of fields as defined in the DOCUMENT table as in the following example:

Forcing the list of fields available in the drop down list. Non existing fields declared in the parameter file are simply ignored. 'anywhere' is always visible. The fields are in alphabetic order.

The Advanced Filter can restrict a search to documents contained in a selected project or assembly. Add a custom condition, select Document is contained, choose in project or in assembly, and select or enter the corresponding ID.

The selected project or assembly is included in the search scope together with all documents contained below it, across every hierarchy level. This condition can be combined with the other Advanced Filter conditions.
Use the Use current selection button to set the search scope from an assembly or project already selected in the MechWorks browser. The button has a document-and-arrow icon and appears next to the value dropdown of each Document is contained condition.
1. Select an assembly or project in a MechWorks browser tree or grid.
2. In the Advanced Filter, click Use current selection on the containment condition you want to update.
3. The selected ID replaces that row's value. The relation automatically switches to in assembly or in project, according to the selected document.
4. Click Search or Working Set when you are ready to run the query.
![]()
In this example, selecting TEST-MAIN (Default) in the browser and clicking the document-and-arrow button sets that assembly as the search scope. Only the condition next to the clicked button is updated; all other conditions and AND/OR groups remain unchanged. This is also useful when the filter contains several containment conditions.
The button uses the last document selected in a MechWorks tree or grid, not in the native CAD tree. With multiple selection, the last selected document is used. If no valid document can be obtained, or the selected document is neither an assembly nor a project, a message is displayed and the condition is left unchanged.
Use current selection and Refresh hierarchies are separate commands. Use current selection copies the selected document into the condition without running a search. The adjacent circular-arrow button, Refresh hierarchies, refreshes the hierarchy data and reloads the available assembly/project IDs.
This feature must be enabled by a database administrator. Run Admin Tools, select Update Database Version, expand General changes for R26, and verify that the update includes the script Add Table DBW_HIERARCHY_FILTER.sql. Click to apply it.

The update creates the DBW_HIERARCHY_FILTER support table. If the table is not available, the hierarchical search option is not displayed. Hierarchy data is prepared in the background when the Advanced Filter is opened and refreshed automatically.
Once you have specified the filters run the query clicking one of the buttons
.
The first applies a normal search and displays the result in the tab of the window below. The second creates a Working Set, which has restricted size limitations but then allows to proceed with batch operations on the query results.
After you have obtained the resulting set of records, you could switch the above tab to preview so as to see the documents as you click the records below.
Two buttons are available on the top of the panel to load and save queries.![]()
If you click any of the two a common Windows dialog appears.
The Default folder is set to %commonprogramfiles(x86)%\Mechworks\Local Queries\ that should be used for test and temporary queries.

Other shared and system queries should be placed on the server.
The file name for Advanced Filter queries are .advflt2 and are not compatible with the ones saved for the previous version of the Advanced Filter. Opening a query does not imply running it automatically.
Every query loaded or saved is added to the list of the 10 most recent queries. To recall a recent query, drop down the list and click one. The name of the query starts with Shared Queries\ or Local Queries\ and is followed by the simple query name as assigned at save time. The Shared and Local labels do not reflect exactly the name of the folder where the queries has been saved, but it is a logical shortcut to find queries quickly with a name that is meant to be human readable.

Recalling a query from the list runs it automatically, unlike with the open button. This was a deliberate choice as often loaded queries are older queries opened to be modified before being executed.
For ordinary document fields, opening the value dropdown retrieves the distinct values available within the branch of the condition you are editing. This helps you build a search progressively, using values compatible with the relevant filters.
The condition being edited does not restrict its own value list. Starting from that condition and following its enclosing groups, an AND applies the constraints from the other branch; an OR does not, because the other branch represents an alternative. Grouping within the applied constraints is preserved. Disabled conditions are ignored, and general search restrictions still apply.
In the following examples, X is the condition whose value dropdown you open:
A AND X: values are restricted by A.
A OR X: A does not restrict the values.
A AND (B OR X): values are restricted by A only.
A OR (B AND X): values are restricted by B only.
(A OR B) AND X: values are restricted by the complete group (A OR B).
A AND (B OR (C AND X)): values are restricted by A AND C.
The list uses the current conditions in the panel when it is opened; you do not need to run Search first. It is not copied from the results grid and may differ from the values shown there, for example after changing a condition without running the search again, or because the condition being edited is excluded from its own value list.

In this AND example, opening the DESCRIPTION dropdown retrieves the distinct descriptions of documents matching COMPANY_ID contains MW and anywhere contains front. The DESCRIPTION condition itself is excluded. The values match the displayed results in this example, but this is not a general rule for value dropdowns.
Set the category to screw, or use an ID condition that identifies screws according to your naming convention. Add a diameter condition joined by AND, then open its value dropdown to see the distinct diameters available for those screws. If the category and ID conditions are alternatives, group them as (Category is screw OR ID matches the screw convention) AND Diameter. You can save the filter for reuse.
Cascading value filtering does not apply to the assembly or project selector in Document is contained. The in assembly and in project dropdowns list the available containers independently of the other conditions. They select where to search, rather than a field value from the matching documents.
A selected containment condition can still restrict an ordinary field dropdown when it is an applicable AND constraint. For example, Document is contained in assembly A AND Description limits the description values to documents within that search scope.
Fields with predefined value lists or special value providers follow their own rules; see Managing linked and special fields.
Linked fields can be difficult to use to filter the Document table because their values can be picked not only from another table but following links of the second degree, which means that getting the values involves querying an intermediate table and a final one linked only to the latter.
The solution for these fields, as well as for fields that require special advanced conditions, is to associate the 2 basic actions:
•Get a list of the existing values
•Apply a filter given a relation (is, contains. Is between, ... ) and the related parameters to stored procedures declared in the database.
Here is how to proceed:
Create a file named PAR\AdvFilterSpecialFields.txt and inside add a list of the field names that must be treated as special, one per line.
In this case we handle only the field SUPPLIER_ID, so we add a single line:
SUPPLIER_ID
In the database we create 2 procedures: one to display the list when the list is dropped down and one to apply the filtering.
The name of the procedures has a fixed part followed by the field name and the name of the parameters must follow the examples displayed below.
The content of the procedure starting after BEGIN is where you develop your custom query or logic.
Example of procedure to retrieve the field values:

CREATE PROCEDURE [dbo].[get_values_for_SUPPLIER_ID]
@projectUids varchar(255)
AS
BEGIN
select name from suppliers where id in (select PrimaryVendorId from AX_InventTable) order by name
RETURN
END
In this case, we get the values from a table linked to a second table, so the degree of the link is 2.
Example of procedure to apply the filtering based on a relation and 2 parameters.
Please note that the procedure must return a recordset of UNIQUE_Ids as int containing the list of DOCUMENTS for which the conditions apply. 
CREATE PROCEDURE [dbo].[filter_uids_for_SUPPLIER_ID]
@relation varchar(50),
@par1 varchar(255),
@par2 varchar(255)
AS
BEGIN
CREATE TABLE #itemIds (id VARCHAR(255))
if @relation = 'is' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME = @par1)
if @relation = 'isnt' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME <> @par1)
if @relation = '<' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME < @par1)
if @relation = '>' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME > @par1)
if @relation = '<=' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME <= @par1)
if @relation = '>=' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME >= @par1)
if @relation = 'isbetween' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME >= @par1)
if @relation = 'contains' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME LIKE '%' + @par1 + '%')
if @relation = 'doesntcontain' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME > @par1 AND NAME < @par2)
if @relation = 'startswith' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME LIKE @par1 + '%')
if @relation = 'doesntstartwith' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME NOT LIKE @par1 + '%')
if @relation = 'endswith' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME LIKE '%' + @par1)
if @relation = 'doesntendwith' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME NOT LIKE '%' + @par1)
if @relation = 'isnull' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME IS NULL)
if @relation = 'isnotnull' insert into #itemIds SELECT ItemId FROM AX_InventTable WHERE PrimaryVendorId IN (SELECT ID FROM SUPPLIERS WHERE NAME IS NOT NULL)
if(NOT EXISTS(SELECT 1 FROM #itemIds))
select 0
else
select unique_id from document where id in (select id from #itemIds)
RETURN
END
In this case we create a temporary table in which we store the list of IDs that fulfill the condition, then use the values in the table to obtain a recordset of the UNIQUE_IDs that we consider valid documents.
Please note that the ideal use of this technique should not return tens of thousands of records, so it fits very well the case when you look for documents associated to a specific supplier but not to all suppliers at once or to all suppliers but one.
See specific topic here.