Get records from group

Sorry, can’t find the answer to this in the forums, and I’m still not at a stage where the help is much use, if it doesn’t pertain to exactly the use-case I’m up against. I’m trying this:

on performSmartRule(theRecords)
	tell application id "DNtp"
		set theGroup to get record at "/Files/More Files" in database "Lots of Files"
		set selection to records in theGroup
		set theSelection to the selection
		repeat with theFiles in theSelection
			set theName to name of theFile
			display dialog theName
		end repeat
	end tell
end performSmartRule

It’s apparent that I can’t set the selection this way - how should it be done? (I’m trying to have a loop going through the records in a smart group in a database - and I don’t know how to define “the records” in the database, so that the repeat loop works). Thanks ppl :slight_smile:

Why would you want to set the selection? I think that

repeat with theRecord in records of theGroup
display dialog (name of theRecord
end repeat

is doing that. The selection is only needed if you want to operate on records (or anything) the user has selected. There’s no point to define it just so that you can iterate through it if there’s a much simpler way to get at the relevant (list of) objects.

–> that leads to “14:26:04: test on performSmartRule (Can’t get every record of smart group id 123456 of database id 2.)” - that’s why I thought I had to define the selection beforehand.

But I’ve figured it out:

on performSmartRule(theRecords)
	tell application id "DNtp"
		set theGroup to get record at "/Files/More Files/" in database "Lots of Files"
		set theFiles to the children of theGroup
		repeat with theFile in theFiles
			set theName to name of theFile
			display dialog theName
		end repeat
	end tell
end performSmartRule

Right. I should have checked the dictionary first. It is children, not records.

it took me an hour though… :exploding_head:

@chrillek is correct on this. The selection is the actual selected items in DEVONthink.