Sorting Filters

In MoneyWorks Gold 7.1.4, it is now possible to use CreateSelection() with the "*Found" and "*Highlight" metasearches to access more tables and list windows than were previously possible (e.g. department, offledger, filter). Access to the transaction selection in the Creditor Mark for Payment list is also possible (that window will override the normal transaction window while it is open).

To illustrate this, here is some sample code for implementing a reorder facility for list filters. There is an Order field by which filters are sorted when inserted into the filter menu. You can change the value of this field using manual Replace or the ReplaceField function. This script provides a UI to do that for you. Note that the Edit Filters window is actually the same window as the Edit Saved Messages that you get from the invoice printing dialog, so you need to look at the window title as well as using the window id specialisation.

constant meta = "Cognito Script Sample"

on Reorder
	let filters = Find("filter.name", "*Found", 999, "\n")
	let filenum = Find("filter.file", "*Found", 1)	// in case other files have filters with same name
	let tabset = Find("filter.tabset", "*Found", 1)	
	let newOrder = ChooseFromList("Drag to reorder", filters, "all,drag")
	let x = 10
	foreach line in text newOrder
		ReplaceField("Filter.Order", "file = " + filenum + " and tabset = " + tabset + " and Name=`" + line + "`", x)
		let x = x + 10
	endfor
end


on Before:F_SAVEDMSGS(w)	
	// window is overloaded, so check title
	if GetFieldValue(w, -1) = "Filter Functions@"
		InstallToolbarIcon(w, "Reorder")
	endif
end
Posted in Sample Code | Comments Off on Sorting Filters