Often I will be reading/browsing an item in DT3 and I want to copy the item link not of that particular document but rather of the group the document is in, i.e. the parent group.
Is there any quick way to do this without backing up to the group, copying the group item link, and then going back to the specific document at hand?
Good moment to ask this question (I stumbled upon it about some days ago):
How do I know which the parent group is? Thereās a parents list in the record structure, but that can of course contain more than one element. I suppose that is needed for replicants so that the parents list contains all the groups where this record is replicated to. So how would one go about to find the parent group of a record?
Noting @cgrunenberg would have to assess the need and feasibility of modifying the parent and location properties for replicants (and it likely isnāt a trivial matter), here is a core approach that could be usedā¦
tell application id "DNtp"
set sel to selection
if sel ā {} then
set selectedItem to item 1 of (selection as list)
set currGroup to {location, name} of current group -- Containing group of the selected file
-- You cannot use the location of a replicated file as it's location is the same as the original parent
-- Process the parents of the selected file
tell selectedItem
set possibleParents to parents whose location does not start with "/Tags/" -- Ignore parents in Tags
repeat with currentPossibility in possibleParents
set currentPossibilityIsWhere to {location, name} of currentPossibility -- Get the location and name of each parent in turn
-- Logging for debugging as this can be a tricky thing to suss out. Comment out as needed
log (currentPossibilityIsWhere as string)
log (currentPossibilityIsWhere & "/" as string = (currGroup & "/" as string)) -- Note appended "/" is required for an = match. I suggest this form.
if (currentPossibilityIsWhere & "/" as string = (currGroup & "/" as string)) then
-- Another log for debugging to verify the correct item link is reported
log (reference URL of currentPossibility as string)
-- Do whatever with the info
set parentURL to (reference URL of currentPossibility)
exit repeat -- Stop processing as the current parent has been matched with the current location
end if
end repeat
end tell
create record with {URL:parentURL, type:bookmark} in incoming group
end if
end tell
Sure, what I meant is: If youāre using item 1 of parents of theRecord in a script be aware that if you move the group (that was parent 1) between script runs youāll get another group with item 1 of parents of theRecord.
Re the script:
If I understand that correctly, youāre using the location property of current group to figure the parent group of the first element of the current selection. Also, if I understand correctly, current group refers to the (currently selected) group of the front most window of the currently selected database. You then compare the location of the recordās parent(s) to the location of the current group (basically, I didnāt see name used).
Given these premises (which might be false, of course): If I select two records in two different groups
which of those is the first in the list?
what is current group in this case?
would it be possible that the first record belongs to a group that is not the current group?
Outside of adding an error trap to check for only one file being selected, the script is intended for getting the item link of a selected file, not multiple selected files.
This whole parent(s) thing is a bit unfortunate, I think. Only replicated records can have more than one parent group, right? So if count of the record's parents is > 1, it is replicated? And only in this case does one have to go through the callisthenics with current group.
Still assuming that all this is correct, wouldnāt it be simpler to have a single parent property referencing the parent group? Thereās a separate replica property, and what does one need the list of all parents for a record for?