Code: Select all
---------------------------------------
-- Function: CopyChildBranch
---------------------------------------
function CopyChildBranch(ptrSrc, ptrTargParent)
local ptrNew = fhCreateItem(fhGetTag(ptrSrc), ptrTargParent)
fhSetValue_Copy(ptrNew, ptrSrc)
local strTag = fhGetTag(ptrSrc)
if strTag == "SOUR2" then -- Found a Source Note
strSour2 = fhGetValueAsText(ptrSrc)
strRecId = string.match(strSour2, "@@S(%d+)@@" ) -- Extract Rec Id from Source Note
local ptrRec = fhNewItemPtr()
ptrRec:MoveToRecordById( "SOUR", strRecId) -- Obtain pointer to Source Record
local ptrNew = fhCreateItem( "SOUR", ptrTargParent ) -- Create the Source Link
fhSetValueAsLink( ptrNew, ptrRec)
else
local ptrNew = fhCreateItem( strTag, ptrTargParent) -- Otherwise just copy original tag
fhSetValue_Copy(ptrNew, ptrSrc)
end
CopyChildren_FromTo(ptrSrc, ptrNew)
end
---------------------------------------
-- Function: CreateCopyChildren_FromTo
---------------------------------------
function CopyChildren_FromTo(ptrFrom, ptrTo)
local ptrF = fhNewItemPtr()
ptrF = ptrFrom:Clone()
ptrF:MoveToFirstChildItem(ptrF)
while ptrF:IsNotNull() do
CopyChildBranch(ptrF, ptrTo)
ptrF:MoveNext()
end
end
--main
local ptrINDI = fhNewItemPtr()
ptrINDI:MoveToFirstRecord("INDI")
while ptrINDI:IsNotNull() do
local ptrUDF = fhGetItemPtr(ptrINDI,"INDI.NICK")
if ptrUDF:IsNotNull() then
local ptrTemp = fhNewItemPtr()
local ptrName = fhGetItemPtr(ptrINDI,"INDI.NAME")
if ptrName:IsNull() then
ptrName = fhCreateItem("NAME",ptrINDI)
end
local ptrNick = fhGetItemPtr(ptrName,"~.NICK")
if ptrNick:IsNull() then
str = fhGetValueAsText(ptrUDF)
str = string.gsub(str,'"','')
ptrNick = fhCreateItem("NICK",ptrName)
fhSetValueAsText(ptrNick,str)
local ptrTemp = fhHasChildItem(ptrUDF)
if fhHasChildItem(ptrUDF) then
local ptrInsert = fhNewItemPtr()
CopyChildren_FromTo(ptrUDF, ptrInsert)
end
fhDeleteItem(ptrUDF) -- delete UDF
end
end
ptrINDI:MoveNext()
end
so now, I have this situation (many) :
0 @I322@ INDI
1 NAME Annabelle /Ames/
2 SOUR @S1467383572@
3 PAGE Year: 1910; Census Place: Township 139, Stark, North Dakota; Roll: T624_1148; Page: 5B; Enumeration District: 0170; FHL microfilm: 1375161
2 SOUR @S1467383564@
2 SOUR @S1467383571@
3 PAGE Year: 1900; Census Place: Township 139, Stark, North Dakota; Roll: 1232; Page: 27B; Enumeration District: 0163; FHL microfilm: 1241232
2 SOUR @S1467383580@
3 PAGE Year: 1880; Census Place: Fisher, Polk, Minnesota; Roll: 629; Family History Film: 1254629; Page: 354C; Enumeration District: 204; Image: 0312
2 SOUR @S1467383566@
3 PAGE Year: 1930; Census Place: McNulty, Columbia, Oregon; Roll: 1941; Page: 3A; Enumeration District: 0013; Image: 629.0; FHL microfilm: 2341675
2 SOUR @S1467383560@
3 PAGE Year: 1860; Census Place: Dunn, Dunn, Wisconsin; Roll: M653_1407; Page: 4; Image: 9; Family History Library Film: 805407
2 SOUR @S1467382567@
1 SEX F <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*******
2 SOUR @@S1467383566@@
3 PAGE Year: 1930; Census Place: McNulty, Columbia, Oregon; Roll: 1941; Page: 3A; Enumeration District: 0013; Image: 629.0; FHL microfilm: 2341675
where the UDF SEX just shows up in some random location in the source list.
using
fhMoveItemBefore(ptrSEX,ptrBIRT)
and use the getchildrenfrom_to do I have to know the SOURnumber ie SOUR12 (whatever) or can I just addItem of type (INDI.NAME.SOUR} if you follow that shorthand?