Code: Select all
from System import * from SoftPro.ClientModel import * from SoftPro.OrderTracking.Client import * from SoftPro.OrderTracking.Client.Orders import * from System.Collections import Queue def Order_RelatedOrders_Validate(args): fake = args.Context.RelatedOrders topFolder = IOrder.Attachments.GetValue(args.Context.Root) file = SearchAttachmentFiles(topFolder) # Search all folders starting with pass one for attachment file meeting search criteria. # Input: folder # Output: AttachmentFile or None if match not found. def SearchAttachmentFiles(topFolder): searchQueue = Queue() searchQueue.Enqueue(topFolder) # Loop until we run out of folders. while searchQueue.Count > 0: folder = searchQueue.Dequeue() for item in folder.Items: if isinstance(item, IAttachmentFolder): # Save folders we find to list of folders to possibly search later. searchQueue.Enqueue(item) elif FoundMatch(item): # Found a file. Check for match. return item # Didn't find a match. return None # Return True if attachment file meets your search criteria. def FoundMatch(file): # If description is filled out and contains our target phrase, return True. return file.Description and 'Hello' in file.Description
- If you want to search starting with a folder below the top level folder, pass the folder to "SearchAttachmentFiles()" and it will search that folder and its children.
- If your match logic in "FoundMatch()" requires the file's folder, it will be "file.Parent".