Sources List for Individual.fh_lua--[[
@Title: Sources List for Individual
@Author: Peter Richmond
@LastUpdated: 01Apr2012
@Version: 1.1
@Description: Lists all Sources 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.
]]
--[[
@function: GetRecordData
@description: Get specified data from a selected Individual or Family record
@parameters: Record Pointer, Data tag, 3 Results tables
@returns: none
@requires: none
]]
function GetRecordData(pr, sTag, tSources, tDRs, tValues)
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, tSources, tDRs, tValues)
else
if string.find(sType, sTag) == 1 then
table.insert(tSources,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]
tSources = {} -- Define array for Sources
tValues = {} -- Define array for Values of Parents of Sources
tDRs = {} -- Define array for Data References
GetRecordData(pi, 'SOUR', tSources, tDRs, tValues)
sTitle = 'Sources for I'..fhGetRecordId(pi)..': '..fhGetDisplayText(pi,'~.NAME','min')
if #tSources == 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('Source', 'item', tSources, #tSources, 400)
end
end
--[[
@Title: Sources List for Individual
@Author: Peter Richmond
@LastUpdated: 01Apr2012
@Version: 1.1
@Description: Lists all Sources 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.
]]
--[[
@function: GetRecordData
@description: Get specified data from a selected Individual or Family record
@parameters: Record Pointer, Data tag, 3 Results tables
@returns: none
@requires: none
]]
function GetRecordData(pr, sTag, tSources, tDRs, tValues)
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, tSources, tDRs, tValues)
else
if string.find(sType, sTag) == 1 then
table.insert(tSources,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]
tSources = {} -- Define array for Sources
tValues = {} -- Define array for Values of Parents of Sources
tDRs = {} -- Define array for Data References
GetRecordData(pi, 'SOUR', tSources, tDRs, tValues)
sTitle = 'Sources for I'..fhGetRecordId(pi)..': '..fhGetDisplayText(pi,'~.NAME','min')
if #tSources == 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('Source', 'item', tSources, #tSources, 400)
end
endSource:Sources-List-for-Individual1.fh_lua