Example Of FindItemsBySQL For Folder

Example Of FindItemsBySQL For Folder
 1# FindItemsBySQL.txt:
 2# Retrieve the contents of a folder
 3# and then filter that folder using a SQL where clause
 4# and order the retrieved items by a specified field.
 5
 6ot = impact.gui.output_toolbox
 7
 8db = impact.active_database
 9
10# insert the number of the folder to search here.
11folder_key = 2084
12
13projects = db.find_folder_by_key(folder_key)
14
15ot.add("folder Name: " + str(projects.folder_name))
16ot.add("folder description: " + str(projects.description))
17ot.add("folder Item Count:" + str(projects.item_count))
18
19# Fields to sort the results by:
20# reference: D_NAME
21# customer: D_CUSTOMER
22# Code: D_CODENUM
23# Created By: D_CREATOR
24# Created Time: D_CRETIME
25# Modified By: D_MODBY
26# Modified Time: D_MODTIME
27# version: D_VERSION
28# description: D_DESCRIPT
29
30# Code: S_CODENUM
31# reference: S_NAME
32# description: S_DESCRIPT
33# Created Time: S_CRETIME
34# Created By: S_CREATOR
35# Modified Time: S_MODTIME
36# Modified By: S_MODBY
37# version: S_VERSION
38
39order_field = "D_MODTIME"
40
41# The direction of the ordering
42# True = asc
43# False = desc
44order_direction = True
45
46# The where clause for the filter
47# insert where clause here
48# can be on any of the columns.
49where_clause = "D_CUSTOMER = 1"
50
51
52items = projects.find_items_by_sql(where_clause, order_direction, order_field)
53
54# Wrap variant return items with Impact.py wrapper
55if items is not None:
56    items = [IDatabaseItem(item) for item in items]
57ot.add(items.count)
58
59for item in items:
60    ot.add("---ITEM---")
61    ot.add("reference: " + str(item.reference))
62    ot.add("customer : " + str(item.customer.name))
63    ot.add("Code: " + str(item.code))
64    ot.add("Created By: " + str(item.created_by.full_name))
65    ot.add("Created Time: " + str(item.created_date_time))
66    ot.add("Modified By: " + str(item.modified_by.full_name))
67    ot.add("Modified Date: " + str(item.modified_date_time))
68    ot.add("version: " + str(item.version))
69    ot.add("description : " + str(item.description))
70    ot.add("----------")