* using search/replace to find empty fact 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
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

using search/replace to find empty fact notes

Post by JoopvB »

I am trying to use search and replace to replace empty fact notes with an [[ auto created note ]]. Seems I am doing something wrong or overseeing the obvious, because when I search on non-empty note fields, everything works fine, but when I leave the search field empty (to search for empty note field), there is no match.

Help is very much appreciated (I have a big database :))!
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: using search/replace to find empty fact notes

Post by tatewise »

No you are not doing anything wrong, because as there is no Note field there is nothing the Plugin can find.
It is not that the Note field is empty, but that the Note field simply does not exist at all.

I presume you have used Tools > Fact Types > Fact > Edit > Advanced to define an Auto-Create Note and wish to add that retrospectively to all existing facts.
If this assumption is correct, why do you only want to deal with empty Note fields.
Is it that you have already dealt with the non-empty Note fields using the Search and Replace Plugin?

One way to locate missing Note fields is to use a Fact Query with a Rows filter:
Exclude unless =IsTrue(%FACT.NOTE2% = "") is true

But you will still have to paste each Note text one by one by hand via the Result Set.

The only way to automate the process is to write a custom Plugin.
Will you need help writing that Plugin?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: using search/replace to find empty fact notes

Post by JoopvB »

You presume right and indeed I already dealt with the non-empty ones and am now in search of means to enter the auto-create note in the facts that (as I understand now) currently have no fact notes.

A Plugin to do this would be great, but on the other hand, would it not be a great extension of the search and replace Plugin to be able to check on missing fact notes (or more general, missing fields)? Maybe a tick box next to the field selection... ?

But if that's not possible or too complex an extension, then I'd be glad to accept your help writing a plugin to automate my replacement challenge (as I said, it's a big database :)).

Thanks.
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: using search/replace to find empty fact notes

Post by tatewise »

Yes, that is too complex to update the Search and Replace Plugin, partly because I would be duty bound to cater for any of the dozens of possibly missing fields in all the various record types. Also, if missing data is to be created there are ambiguous interpretations. If say you set Search Scope to Education (INDI.EDUC) and specified Note fields as Fact Notes (~Fact.NOTE) then it is fairly clear that missing Note fields (INDI.EDUC.NOTE) fields should be created, but does it also mean that an Education fact (INDI.EDUC) should be created if missing from any Individual? There are many other such ambiguous cases.

It is too late here now to start on a new Plugin, but you could study the plugins:index|> Family Historian Plugins section, especially the plugins:getting_started|> Getting Started Writing Plugins Introduction.

I will be back later.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
tatewise
Megastar
Posts: 28414
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: using search/replace to find empty fact notes

Post by tatewise »

I imagine the [[ text ]] you wish to create is a consequence of the split notes delimiter options (12606) discussion.

How familiar are you with programming languages?
If you have used languages such as Visual Basic, or C++, etc, then the concepts in Lua will be soon understood.
If not, then it will take a little longer.

Have you found the Help on How to Write Plugins?
Try some of the examples, but at least review all the steps from 1. to 6.

Checkout the Sample Plugin Scripts, especially List All UDF Fields, as we may be using a similar technique to loop through records and find all Facts by substituting the fhIsFact(ptrItem) function instead of fhIsUDF(ptrItem).

Can you please clarify which Facts need the Note field text to be created.
Is it all Facts and they all need the same Note field text?
OR is it a subset of Facts and does each type need different Note field text?
If the latter, then please give at least a few examples if not an entire list.
When programming, it is important to have a precise definition of the objectives before starting.
Also remember that programming languages need precise instructions ~ even the slightest mistake will result in failure.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: using search/replace to find empty fact notes

Post by JoopvB »

I have been programming in PL/1, APL, Fortran, Algol and lately in Python, but know nothing of Lua.
Yes I checked the Plugin Help.

I am now looking into the Birth fact, after that facts like Death, Burial, Baptism, and Marriage need to be handled. Every different fact will need to have a different auto-create note.

But I have been thinking of a way to make things simpler (I think :)). If we could have a straight forward Plugin to just create a fact note (of fact type X) with some uniquely chosen text in it, then your search and replace would do the rest of the job by just changing that text to whatever I need. A kind of two steps approach with very little (extra) work and maximum flexibility.

What do you think? Doable? And if so could you give me some kind of snippet (or skeleton code) to build a Plugin to create a note field (if not one exists) with text to be specified for a fact type to be specified?
User avatar
Jane
Site Admin
Posts: 8514
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: using search/replace to find empty fact notes

Post by Jane »

Try this.
Change the notecontents between [[ and ]] to match the text you want.
If you are doing marriage change 'INDI' for 'FAM'
and set the factid to the correct id

Code: Select all

--[[
@Title:Loop Fact Type and add note if none exists.
@Author: Jane Taubman  
@Version: 0.0
@LastUpdated: 
@Description: 
]]
local notecontents = [[
New note contents here
]]
local recordType = 'INDI'
local factid = 'BIRT'

function main()
    local recordType = 'INDI'
    local factid = 'BIRT'
    for pi in records(recordType) do
        local pf,pn = fhNewItemPtr(),fhNewItemPtr()
        pf:MoveTo(pi,'~.'..factid)
        while pf:IsNotNull() do
            pn:MoveTo(pf,'~.NOTE2')
            if pn:IsNull() then
                pn = fhCreateItem('NOTE2', pf)
                fhSetValueAsText(pn,notecontents)
            end
            pf:MoveNext("SAME_TAG")
        end
    end
end

------------------------------------------------------ functions

function records(type)
local pi = fhNewItemPtr()
local p2 = fhNewItemPtr()
pi:MoveToFirstRecord(type)
return function ()
p2:MoveTo(pi)
pi:MoveNext()
if p2:IsNotNull() then return p2 end
end
end
------------------------------------------------------ main
main()
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: using search/replace to find empty fact notes

Post by JoopvB »

Hi Jane,

Thanks for your help. It works beautifully. One question though, to have it fill in the right auto-create note right away, I need to enter [[ and ]] as text to enter as well. Suppose the auto-text is:

[[
Variable 1:
Variable 2:
]]

Could this be entered in one go? Would be great.

Cheers, Joop
User avatar
Jane
Site Admin
Posts: 8514
Joined: 01 Nov 2002 15:00
Family Historian: V7
Location: Somerset, England
Contact:

Re: using search/replace to find empty fact notes

Post by Jane »

The quick and dirty way use double curly brackets and replace them with square ones. In theory you should be able to escape with a \ but it was not working for me.

Code: Select all

local notecontents = [[
{{New note contents here}}
]]
notecontents = notecontents:gsub('{{','[[')
notecontents = notecontents:gsub('}}',']]')
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: using search/replace to find empty fact notes

Post by JoopvB »

Super, I like quick and don't mind dirty :). It does the job and has improved my understanding and interest of Lua.

Thanks again.
Post Reply