* Creating Research Notes

For users to report plugin bugs and request plugin enhancements; and for authors to test new/new versions of plugins, and to discuss plugin development (in the Programming Technicalities sub-forum). If you want advice on choosing or using a plugin, please ask in General Usage or an appropriate sub-forum.
Post Reply
User avatar
Mark1834
Megastar
Posts: 2458
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Creating Research Notes

Post by Mark1834 »

I'll put this as a separate and probably fairly short thread to avoid clutter.

I'm writing a plugin that creates a new Research Note and populates it with specified text. I'm missing something obvious (or maybe obscure ;)).

For a simple Note the following code works fine:

Code: Select all

p1 = fhCreateItem('NOTE')
p2 = fhCreateItem('TEXT', p1)

fhSetValueAsText(p2, 'This is my text')
print(fhGetValueAsText(p2))
If I try completely analogous code for a Research Note, the record is created, but with no text

Code: Select all

p1 = fhCreateItem('_RNOT')
p2 = fhCreateItem('TEXT', p1)

fhSetValueAsText(p2, 'This is my text')
print(fhGetValueAsText(p2))
Looping through existing Research Notes, fhGetTag(p2) confirms that 'TEXT' is the correct tag, and %_RNOT.TEXT% is the correct data reference in the Query window when querying Research Notes, and fhGetValueAsText(p2) pulls out the text correctly from existing Research Notes.

My plugin is nearly done, but I've fallen within sight of the finishing post. Why can't I populate the text field of a new Research Note? Is there a silly mistake here I've missed?
Mark Draper
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Creating Research Notes

Post by tatewise »

I get the same symptoms! Looks like a bug to me.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
Mark1834
Megastar
Posts: 2458
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Creating Research Notes

Post by Mark1834 »

OK, thanks - glad it's not me going mad :).

I'll report it to CP. In the meantime, I'll finalise my plugin with standard notes and just change that one line when the bug is fixed.
Mark Draper
User avatar
Mark1834
Megastar
Posts: 2458
Joined: 27 Oct 2017 19:33
Family Historian: V7
Location: South Cheshire, UK

Re: Creating Research Notes

Post by Mark1834 »

Reported to CP, and received a detailed explanation of what we are seeing :).

There is a subtle difference between Notes and the new Research Notes that we had not spotted. For Note Records, you have to create the new Record and its TEXT field separately, as per the code above. For the new Research Note Record, the TEXT field is created automatically when the record is created.

In the code above, p2 has a value of nil after the call to fhCreateItem, as the TEXT field exists already, and as only one is permitted, the function call fails and returns a nil value. This can be confirmed in the debugger.

The solution is to either call fhCreateItem with a value of true for the optional ReuseEmpties third parameter that defaults to false, or to use the existing newly-created empty TEXT field rather that try to create a new one. Corrected code is show below, and both versions work as intended:

Code: Select all

-- option 1

p1 = fhCreateItem('_RNOT')
p2 = fhCreateItem('TEXT', p1, true)

fhSetValueAsText(p2, 'This is my text')
print(fhGetValueAsText(p2))

-- option 2

p1 = fhCreateItem('_RNOT')
p2 = fhNewItemPtr()

p2:MoveTo(p1, "~.TEXT")
fhSetValueAsText(p2, 'This is my text')
print(fhGetValueAsText(p2))
Now we know Research Notes can be populated in code, I will convert the development plugin to Import RootsMagic ToDo List to work with Research Notes for FH7 as intended originally as they would be the preferred option. Rather than exclude FH6 users completely, I will set it up to import as standard Notes in FH6. Standard Notes need a bit more work to display optimally and keep separate from all the other Note Records that a typical Project has, but they are better than nothing for the sake of a few extra lines of code.
Mark Draper
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Creating Research Notes

Post by ColeValleyGirl »

You might want to consider marking Standard Notes with a #tag like #Research in V6.
Post Reply