A question on (parents of theRecord) and (tags of theRecord)

I look at the std script “Add tags to selection” and the script is using the following code for appending tags.

set tags of theRecord to ( parents of theRecord) & theTags

According to the dictionary it is more like this

set tags of theRecord to ( tags of theRecord) & theTags

Parents is not a property in the dictionary but its literally meaning can include parent group, tags, and group tags of a record. Perhaps that why both lines achieve the same purpose. Is there a difference between the two?

Thanks

It is actually:


Anyway, both versions should work, the first version is used by some older scripts.

Thanks!
I search for “parents”, somehow the search index in dictionary (script editor or script debugger) only returns results for “parent”!

Is there a way to assign one/more group tag to an item by script other than by replicating the item into the group. The above-mentioned code only assign ordinary tag to an item.

Thank you in advance.

Are groups excluded from tagging, see File > Database Properties, or not?

No, and I can see that the group is displayed as a tag icon.
I am sure that the name I use for the group tag is unique in the database, but when I run the script, a new ordinary tag of the same name is cerated instead of assigning the group-tag to the item.

I am just trying to clarify whether the above-mentioned tow lines of code in the 1st post are supposed to work for group-tag, too. If not, I’ll try to find other alternatives - not an issue at all.

How does the complete script look like?

Just an extraction of the relevant block. One limitation I have is the list I create is a list returning names (for selection) and not records (like the group selector), else it would be straight forward…


tell application id "DNtp"
	try
		set theSortTags to (name of every parent of current database whose (tag type is group tag))
		
		if theSortTags is {} then
			display alert "This database does not have any group tag" giving up after 1
			set theTagList to {}
		else
			my QsortList(theSortTags, 1, count theSortTags) -- not relevant
			set theTagList to (choose from list theSortTags with prompt {"Choose group tags to apply: (you can select none)"} default items "" with multiple selections allowed and empty selection allowed)  
		end if
		
		repeat with theRecord in theRecords
			set tags of theRecord to (tags of theRecord) & theTagList
		end repeat
		
	end try
end tell

On second thought, I can make a list that return the objects! (1) make a list1 of records (2) make a matching list2 of names of records (3) select the names from list2 (4) select the items in list1 according to the positions of the chosen items in list2. Then I can simplify the ongoing manipulation. (on third thought, no. Coz I want to sort the names but I can’t sort the objects by name in list1 - so matching position is not possible.)

This scripts works fine in a test database containing the groups A & B:

tell application id "DNtp"
	try
		set theRecords to the selection
		set theSortTags to (name of every parent of current database whose (tag type is group tag))
		
		if theSortTags is {} then
			display alert "This database does not have any group tag" giving up after 1
			set theTagList to {}
		else
			set theTagList to (choose from list theSortTags with prompt {"Choose group tags to apply: (you can select none)"} default items "" with multiple selections allowed and empty selection allowed)
		end if
		
		repeat with theRecord in theRecords
			set tags of theRecord to (tags of theRecord) & theTagList
		end repeat
		
	end try
end tell

Thanks. I will try running in different group tag set up again. Perhaps there are duplicated names for the groups that I’m not aware of (will run search to see if that’s the case).

Cheers