* Populating citation fields in a prepared citation
-
shoshk
- Famous
- Posts: 242
- Joined: 13 May 2015 16:28
- Family Historian: V7
- Location: Mitzpe Jericho, Israel
Populating citation fields in a prepared citation
I can't figure out how to set values for citation fields in a prepared citation (pCite). Can somebody help?
Shosh Kalson
- Jane
- Site Admin
- Posts: 8440
- Joined: 01 Nov 2002 15:00
- Family Historian: V7
- Location: Somerset, England
- Contact:
Re: Populating citation fields in a prepared citation
The fhUtils pCite option is read only, so you will need to access the fields directly via the HEAD record and the _PCIT field.
Have a look at the source for the loadPreparedCitation in the fhutils source for ideas.
Have a look at the source for the loadPreparedCitation in the fhutils source for ideas.
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
- ColeValleyGirl
- Megastar
- Posts: 4853
- Joined: 28 Dec 2005 22:02
- Family Historian: V7
- Location: Cirencester, Gloucestershire
- Contact:
Re: Populating citation fields in a prepared citation
If you're struggling to work out the data references, I ended up looking at the header record in the Gedcom to work them out.
Helen Wright
ColeValleyGirl's family history
ColeValleyGirl's family history
- tatewise
- Megastar
- Posts: 27078
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Populating citation fields in a prepared citation
It depends on what kinds of Citation fields.
(1) Generic GEDCOM citation fields will have standard data references such as:
%HEAD._PCIT.SOUR.PAGE% is Where within Source
%HEAD._PCIT.SOUR.DATA.DATE% is Entry Date
%HEAD._PCIT.SOUR.DATA.TEXT% is Text from Source
(2) For metafields there are multiple instances of %HEAD._PCIT.SOUR._FIELD[n]%
That data reference must be changed to its metafield shortcut:
local strMeta = fhGetMetafieldShortcut(ptrMeta)
local ptrMeta = fhGetItemPtr(ptrSour,"~." .. strMeta)
Then you can use such as fhSetValueAsText(ptrMeta,"New Text")
e.g.
(1) Generic GEDCOM citation fields will have standard data references such as:
%HEAD._PCIT.SOUR.PAGE% is Where within Source
%HEAD._PCIT.SOUR.DATA.DATE% is Entry Date
%HEAD._PCIT.SOUR.DATA.TEXT% is Text from Source
(2) For metafields there are multiple instances of %HEAD._PCIT.SOUR._FIELD[n]%
That data reference must be changed to its metafield shortcut:
local strMeta = fhGetMetafieldShortcut(ptrMeta)
local ptrMeta = fhGetItemPtr(ptrSour,"~." .. strMeta)
Then you can use such as fhSetValueAsText(ptrMeta,"New Text")
e.g.
Code: Select all
local ptrHead = fhNewItemPtr()
ptrHead:MoveToFirstRecord("HEAD")
local ptrSour = fhGetItemPtr(ptrHead,"~._PCIT.SOUR")
local ptrDate = fhGetItemPtr(ptrSour,"~.DATA.DATE")
local ptrMeta = fhGetItemPtr(ptrSour,"~._FIELD")
local strMeta = fhGetMetafieldShortcut(ptrMeta)
local ptrMeta = fhGetItemPtr(ptrSour,"~."..strMeta)
fhSetValueAsText(ptrMeta,"New Text")
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
-
shoshk
- Famous
- Posts: 242
- Joined: 13 May 2015 16:28
- Family Historian: V7
- Location: Mitzpe Jericho, Israel
Re: Populating citation fields in a prepared citation
I have no problem setting values for fields associated with the source.
I cannot set the values for citation-specific fields.
I use createUpdateItem to set values for fields associated with the source. It works fine.
When I try to use it for citation-specific fields, it doesn't work. I get the message "createUpdateItem - failed to create ~.DT-SupDate.
My code looks like this:
I cannot set the values for citation-specific fields.
I use createUpdateItem to set values for fields associated with the source. It works fine.
When I try to use it for citation-specific fields, it doesn't work. I get the message "createUpdateItem - failed to create ~.DT-SupDate.
My code looks like this:
Code: Select all
local ptrBase = fhNewItemPtr()
ptrBase:MoveToFirstRecord('HEAD')
local ptr = fhGetItemPtr(ptrBase,'~._PCIT')
local pSource = fhGetItemPtr(ptr,'~.SOUR>')
fh.createUpdateItem(pSource, '~.DT-SupDate', util.GetTodayAsText())
Shosh Kalson
- tatewise
- Megastar
- Posts: 27078
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Populating citation fields in a prepared citation
When you use SOUR> that sets the pointer to the Source record and NOT the Citation. ( Note the > )
You must use SOUR without > which sets the pointer to the Citation as in my script:
local ptrHead = fhNewItemPtr()
ptrHead:MoveToFirstRecord("HEAD")
local ptrSour = fhGetItemPtr(ptrHead,"~._PCIT.SOUR")
Also, I think the metafield shortcut is using the wrong syntax and should be:
'~.~DT-SupDate'
It is important to understand the difference between SOUR> & SOUR and PLAC> & PLAC and FAMS> & FAMS, etc.
The former of each pair follow the link to point to another record.
The latter of each pair refers to the tag in this record that holds the pointer.
You must use SOUR without > which sets the pointer to the Citation as in my script:
local ptrHead = fhNewItemPtr()
ptrHead:MoveToFirstRecord("HEAD")
local ptrSour = fhGetItemPtr(ptrHead,"~._PCIT.SOUR")
Also, I think the metafield shortcut is using the wrong syntax and should be:
'~.~DT-SupDate'
It is important to understand the difference between SOUR> & SOUR and PLAC> & PLAC and FAMS> & FAMS, etc.
The former of each pair follow the link to point to another record.
The latter of each pair refers to the tag in this record that holds the pointer.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
-
shoshk
- Famous
- Posts: 242
- Joined: 13 May 2015 16:28
- Family Historian: V7
- Location: Mitzpe Jericho, Israel
Re: Populating citation fields in a prepared citation
Mike, thank you, thank you, thank you! I wouldn't have solved this without your help.
BTW, the syntax ~DT-SupDate works fine.
BTW, the syntax ~DT-SupDate works fine.
Shosh Kalson
- tatewise
- Megastar
- Posts: 27078
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Populating citation fields in a prepared citation
Shos, I think some typos may be creeping in.
Your earlier script used ~.DT-SupDate with a tilda and a dot, which I think is wrong.
Now you have posted ~DT-SupDate with a tilda but no dot, which is the correct shortcut format.
But when used as a relative data ref parameter that must be prefixed with ~. producing ~.~DT-SupDate
So it depends on the context.
fhCreateItem( '~DT-SupDate', ptrParent )
fhGetItemPtr( ptrParent, '~.~DT-SupDate' )
I use the following to compose the shortcut
fhGetMetafieldShortcut(...)
Your earlier script used ~.DT-SupDate with a tilda and a dot, which I think is wrong.
Now you have posted ~DT-SupDate with a tilda but no dot, which is the correct shortcut format.
But when used as a relative data ref parameter that must be prefixed with ~. producing ~.~DT-SupDate
So it depends on the context.
fhCreateItem( '~DT-SupDate', ptrParent )
fhGetItemPtr( ptrParent, '~.~DT-SupDate' )
I use the following to compose the shortcut
fhGetMetafieldShortcut(...)
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry