Notes List for Individual.fh_lua

--[[
@Title:	Notes List for Individual
@Type: Standard
@Author:	Peter Richmond
@Version: 	1.3
@LastUpdated:	10AMar2021
@Licence: This plugin is copyright (c) 2020 Peter Richmond & contributors and is licensed under the MIT License which is hereby incorporated by reference (see https://pluginstore.family-historian.co.uk/fh-plugin-licence)
@Description:	Lists all Notes linked to a selected Individual.
Works best if Added to the Tools Menu.  Then select an Individual
(in Focus or Records window or Diagram) and click on the entry in the Tools Menu.
@V1.3: Tested for FHv7.
]]

--[[
@function: GetRecordData
@description: Get specified data from a selected Individual or Family record
@parameters: Record Pointer, Data tag
@returns: none
@requires: none
]]
function GetRecordData(pr, sTag)
   local p1 = fhNewItemPtr()
	local pr1 = pr:Clone()
	p1:MoveToFirstChildItem(pr)
	while p1:IsNotNull() and (pr1:IsSame(pr) or pr1:IsSame(pi)) do
		local sType = fhGetTag(p1)
		if sType == 'FAMS' then		-- get data from Family-as-Spouse record
			GetRecordData(fhGetValueAsLink(p1), sTag)
		else
			if string.find(sType, sTag) == 1 then
				table.insert(tNotes,p1:Clone())
				table.insert(tDRs,BuildDR(p1))
				pr1:MoveToParentItem(p1)
				sValue = fhGetDisplayText(pr1)
				if not fhHasParentItem(pr1) then
					sValue = 'Record: ' .. sValue
				end
				table.insert(tValues,sValue)
			end
		end
		p1:MoveNextSpecial()
		pr1:MoveToRecordItem(p1)
	end
end

--[[
@function: BuildDR
@description: Get Data Reference for Tag
@parameters: Item Pointer
@returns: Data reference String (excluding index)
@requires: none
]] 
function BuildDR(ptr)
   local ptrTemp = fhNewItemPtr()
   ptrTemp:MoveTo(ptr)
   strDR = fhGetTag(ptrTemp)
   while fhHasParentItem(ptrTemp) do
      ptrTemp:MoveToParentItem(ptrTemp)
      strDR = fhGetTag(ptrTemp)..'.'..strDR
   end
   return strDR
end

-- Check Individual selected
tIndi = fhGetCurrentRecordSel('INDI')
if #tIndi == 0 then
    fhMessageBox('No Individual Selected')
else
	pi = tIndi[1]
	tNotes = {}		-- Define array for Notes
	tValues = {}		-- Define array for Values of Parents of Notes
	tDRs = {}		-- Define array for Data References

	GetRecordData(pi, 'NOTE')
	
	sTitle = 'Notes for I'..fhGetRecordId(pi)..': '..fhGetDisplayText(pi,'~.NAME','min')
	if #tNotes == 0 then
		fhMessageBox('No ' .. sTitle)
	else
		fhOutputResultSetTitles(sTitle, sTitle)
		fhOutputResultSetColumn('DataRef (w/o Index)', 'text', tDRs, #tDRs, 100)
		fhOutputResultSetColumn('Field', 'text', tValues, #tValues, 200)
		fhOutputResultSetColumn('Note (double-clickable)', 'item', tNotes, #tNotes, 400)
	end
end

Source:Notes-List-for-Individual.fh_lua