labeling groups depending on labels inside the group

Morning.

I’ld like to set the label of a group automatically depending on labels of the items inside the group, e.g.:

IF at least one item inside GROUP has NO LABEL
SET LABEL of GROUP to RED
ELSE
IF at least one item inside GROUP has LABEL YELLOW
SET LABEL of GROUP to YELLOW
ELSE
SET LABEL of GROUP to GREEN

How can I do this?

Thanks in advance for your support!

Kind regards, Friedrich

tell application id "com.devon-technologies.thinkpro2"
	set gr to (get record at "/Inbox/New Group 4") of current database
	set labelReport to (label of (children of gr))
	if every item of labelReport = 0 then -- No Labels
		set label of gr to 1
	else if labelReport contains 4 then -- At least one Yellow
		set label of gr to 4
	else -- Any file, any color = Green
		set label of gr to 2
	end if
end tell

```This is a five minute bit of code (though I'd probably opt to trigger this instead of hardcoding the location). Note that you'd have to change this if you've changed the colors of your Labels in Preferences > Colors.