* fhCreateItem - Anomaly ?
fhCreateItem - Anomaly ?
I am trying to develop a pluging to add probate information
I have written the following function to add items to the individual.
function AddInfo(ptr, Type, Value)
if Value==nil then
return
end
infoPtr=fhGetItemPtr(ptr,'~.'..Type)
if infoPtr:IsNull() then
infoPtr= fhCreateItem(Type, ptr)
end
fhSetValueAsText(infoPtr, Value)
end
This function works fine if I use DATE,PLAC and ADDR as the Type parameter.
However, if I supply NOTE or TEXT as the Type parameter, the sub item is not created.
The Call stack on entering this function is:
After attempting to create the sub item, the call stacks shows the following value for the ptr:
Is there something special about these sub types that need to be handled differently.
I have written the following function to add items to the individual.
function AddInfo(ptr, Type, Value)
if Value==nil then
return
end
infoPtr=fhGetItemPtr(ptr,'~.'..Type)
if infoPtr:IsNull() then
infoPtr= fhCreateItem(Type, ptr)
end
fhSetValueAsText(infoPtr, Value)
end
This function works fine if I use DATE,PLAC and ADDR as the Type parameter.
However, if I supply NOTE or TEXT as the Type parameter, the sub item is not created.
The Call stack on entering this function is:
After attempting to create the sub item, the call stacks shows the following value for the ptr:
Is there something special about these sub types that need to be handled differently.
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: fhCreateItem - Anomaly ?
Yes, that is a common pitfall.
The Type tag NOTE identifies a 'Link to Note record' as indicated in your screenshot.
To create a local Note you need to use the NOTE2 Type tag.
TEXT is a not a valid Type tag in the context of a Fact. What Value are you trying to create?
BTW: My I suggest the following structure for your function to avoid the explicit return and use a local variable:
The Type tag NOTE identifies a 'Link to Note record' as indicated in your screenshot.
To create a local Note you need to use the NOTE2 Type tag.
TEXT is a not a valid Type tag in the context of a Fact. What Value are you trying to create?
BTW: My I suggest the following structure for your function to avoid the explicit return and use a local variable:
Code: Select all
function AddInfo(ptr, Type, Value)
if Type and Value then
local infoPtr = fhGetItemPtr(ptr,'~.'..Type)
if infoPtr:IsNull() then
infoPtr = fhCreateItem(Type, ptr)
end
fhSetValueAsText(infoPtr, Value)
end
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: fhCreateItem - Anomaly ?
Thanks Mike
The NOTE2 type does the trick.
I appreciate your advice on error handling. I was concentrating on functionality first, then building in error handling.
As for the TEXT type, I was trying to generate a source record and include the text as part of that source. I am sure there is a better way than I have looked at so far. Looking at the GEDCOM file, it seemed a possible way to add TEXT and CONT records using this technique.
Any advice would be appreciated.
The NOTE2 type does the trick.
I appreciate your advice on error handling. I was concentrating on functionality first, then building in error handling.
As for the TEXT type, I was trying to generate a source record and include the text as part of that source. I am sure there is a better way than I have looked at so far. Looking at the GEDCOM file, it seemed a possible way to add TEXT and CONT records using this technique.
Any advice would be appreciated.
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: fhCreateItem - Anomaly ?
Firstly, to discover Type tags such as NOTE2 the tip is to open the Query Window and use the Fields data reference assistant.
Under the box bottom left, click the ▼ button and choose Show Both in Box.
Then navigate through the data references above to discover the field required.
In this thread's context, navigate into any fact and choose Note and the box below will reveal the NOTE2 tag.
If you choose Date or Place> instead, the box will reveal the DATE and PLAC tags.
When you say you want to generate a source record, I assume you mean you want to add a Citation to the Probate fact that links to a Source record.
So back in the Query Window, under a fact, choose Source> to reveal the SOUR tag which is the Citation field that must hold the link pointer to a Source record.
If you want to link to an existing Source record then its record pointer must be discovered.
If you want to create a new Source record then that must be done first to obtain its record pointer.
Then the Value for the SOUR tag will be that pointer, but must use fhSetValueAsLink(infoPtr, Value) in your function.
Creating a whole new Source record is another ball game that needs further discussion.
However, to reveal the field tags involved, back in the Query Window, where you have chosen Source>, click the [+] on its left to expand its fields. Ignore the ones in brackets ( ... ) which are Citation-specific fields. Scroll down to the Author through to Note fields, where Text from Source reveals the TEXT tag, which is probably what you were thinking of using.
When you are familiar with this Query Window technique we can discuss how to create a Source record and add its fields.
Under the box bottom left, click the ▼ button and choose Show Both in Box.
Then navigate through the data references above to discover the field required.
In this thread's context, navigate into any fact and choose Note and the box below will reveal the NOTE2 tag.
If you choose Date or Place> instead, the box will reveal the DATE and PLAC tags.
When you say you want to generate a source record, I assume you mean you want to add a Citation to the Probate fact that links to a Source record.
So back in the Query Window, under a fact, choose Source> to reveal the SOUR tag which is the Citation field that must hold the link pointer to a Source record.
If you want to link to an existing Source record then its record pointer must be discovered.
If you want to create a new Source record then that must be done first to obtain its record pointer.
Then the Value for the SOUR tag will be that pointer, but must use fhSetValueAsLink(infoPtr, Value) in your function.
Creating a whole new Source record is another ball game that needs further discussion.
However, to reveal the field tags involved, back in the Query Window, where you have chosen Source>, click the [+] on its left to expand its fields. Ignore the ones in brackets ( ... ) which are Citation-specific fields. Scroll down to the Author through to Note fields, where Text from Source reveals the TEXT tag, which is probably what you were thinking of using.
When you are familiar with this Query Window technique we can discuss how to create a Source record and add its fields.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: fhCreateItem - Anomaly ?
Thanks for this. As always, your knowledge and advice is invaluable.
With many years writing software, my approach to this has been from the GEDCOM file, which would have been the easier option for me to work on. But where is the learning curve in that.
I have been using Ancestral Sources to add information directly rather than importing from FindMyPast GEDCOM files.
I have used fhSetValueAsLink already in another plugin I have written so am aware I need to do that.
You are right in that in generating a source record, I really want to add a Citation to the Probate fact that links to a Source record.
Simply I was trying to emulate the source record from Ancestral Sources; e.g.
0 @S101@ SOUR
1 TITL Death Blackburn, Lancashire, England 1896 Rebecca Whiteside
1 _TYPE Death
1 PUBL 1896/8E/223
1 TEXT <clr="00007F"><b><fs="+1">Death</clr></b></fs>
2 CONT <clr="00007F">Reference: </clr>1896/8E/223
2 CONT <clr="00007F">Death date: </clr>1896
2 CONT <clr="00007F">Death place: </clr>Blackburn, Lancashire, England
2 CONT <clr="00007F">Name: </clr>Rebecca Whiteside
2 CONT <clr="00007F">Gender: </clr>female
2 CONT <clr="00007F">Date of birth: </clr>1876
2 _FMT 1
1 REPO @R1@
I have created a simple TEXT item in the source. The next challenge is to be to add the 'CONT' lines, to the source text.
I am trying to learn a step at a time.
With many years writing software, my approach to this has been from the GEDCOM file, which would have been the easier option for me to work on. But where is the learning curve in that.
I have been using Ancestral Sources to add information directly rather than importing from FindMyPast GEDCOM files.
I have used fhSetValueAsLink already in another plugin I have written so am aware I need to do that.
You are right in that in generating a source record, I really want to add a Citation to the Probate fact that links to a Source record.
Simply I was trying to emulate the source record from Ancestral Sources; e.g.
0 @S101@ SOUR
1 TITL Death Blackburn, Lancashire, England 1896 Rebecca Whiteside
1 _TYPE Death
1 PUBL 1896/8E/223
1 TEXT <clr="00007F"><b><fs="+1">Death</clr></b></fs>
2 CONT <clr="00007F">Reference: </clr>1896/8E/223
2 CONT <clr="00007F">Death date: </clr>1896
2 CONT <clr="00007F">Death place: </clr>Blackburn, Lancashire, England
2 CONT <clr="00007F">Name: </clr>Rebecca Whiteside
2 CONT <clr="00007F">Gender: </clr>female
2 CONT <clr="00007F">Date of birth: </clr>1876
2 _FMT 1
1 REPO @R1@
I have created a simple TEXT item in the source. The next challenge is to be to add the 'CONT' lines, to the source text.
I am trying to learn a step at a time.
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: fhCreateItem - Anomaly ?
The short answer is that you cannot add CONT tags via Plugins.
What you do is compose the Value for the TEXT tag with newline \n characters for each line break.
i.e. The Text Value looks like it does when viewed in the Property Box.
FH automatically adds the CONT tags to the GEDCOM file.
Back in the Query Window data references you will never find CONT or CONC tags.
When a TEXT field or NOTE2 field is examined in the FH GUI you see a multi-line text box.
Notice the REPO tag with a link to the Repository record.
The Citation SOUR tag must have a similar link to your Source record.
However, in Plugins, you must use record pointer values, not GEDCOM cross-refs like @S101@.
What you do is compose the Value for the TEXT tag with newline \n characters for each line break.
i.e. The Text Value looks like it does when viewed in the Property Box.
FH automatically adds the CONT tags to the GEDCOM file.
Back in the Query Window data references you will never find CONT or CONC tags.
When a TEXT field or NOTE2 field is examined in the FH GUI you see a multi-line text box.
Notice the REPO tag with a link to the Repository record.
The Citation SOUR tag must have a similar link to your Source record.
However, in Plugins, you must use record pointer values, not GEDCOM cross-refs like @S101@.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: fhCreateItem - Anomaly ?
Thanks for your help/advice.
I have managed to get the source/citation records added and linked to the probate event and the death fact if appropriate.
This has been a good learning experience as well as being of practical use.
I have managed to get the source/citation records added and linked to the probate event and the death fact if appropriate.
This has been a good learning experience as well as being of practical use.
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: fhCreateItem - Anomaly ?
Excellent. Here's one more tip...
In your screenshot, the Text from Source (TEXT) field uses Rich Text codes.
To enable those, the 2 _FMT 1 tag line is required, but you cannot add that directly with a Plugin script.
You must use the fhSetValueAsRichText(...) function to enable the Rich Text formatting.
In your screenshot, the Text from Source (TEXT) field uses Rich Text codes.
To enable those, the 2 _FMT 1 tag line is required, but you cannot add that directly with a Plugin script.
You must use the fhSetValueAsRichText(...) function to enable the Rich Text formatting.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Re: fhCreateItem - Anomaly ?
Thanks for all your advice and encouragement.
I now have a functional plugin that can create a probate event and, if appropriate, add the residence at time of death and add/update the death fact. It generates a source/citation record and links them into the the relevant fact/events. The input is via a fh.GetParam dialog, and the contents of that dialog is transferred to the 'text from source' in the source record.
Once I have tidied up the code, I thought about starting a new thread here explaining the plugin in more detail to see if it would be of interest to a wider audience.
I now have a functional plugin that can create a probate event and, if appropriate, add the residence at time of death and add/update the death fact. It generates a source/citation record and links them into the the relevant fact/events. The input is via a fh.GetParam dialog, and the contents of that dialog is transferred to the 'text from source' in the source record.
Once I have tidied up the code, I thought about starting a new thread here explaining the plugin in more detail to see if it would be of interest to a wider audience.
Re: fhCreateItem - Anomaly ?
I would be very interested to see the plugin please. I do write the occasional simple plugin myself, and I've been considering writing something along the lines you have just completed. Thank you for offering to share.
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
Re: fhCreateItem - Anomaly ?
I'd also like to echo your thanks to Mike Tate, who has given a lot of advice to myself and others on plugins.
Adrian Cook
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
Researching Cook, Summers, Phipps and Bradford, mainly in Wales and the South West of England
- tatewise
- Megastar
- Posts: 27074
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: fhCreateItem - Anomaly ?
Normie, in that thread, you can simply Attach the Plugin file to the posting with a brief description of its purpose.
The Plugin script should have sufficient comments and be well structured to make it clear how it operates without needing any other explanations.
The Plugin script should have sufficient comments and be well structured to make it clear how it operates without needing any other explanations.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry