* Obvious problem not staring me in the face

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
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Obvious problem not staring me in the face

Post by ColeValleyGirl »

Can I ask for a new pair of eyes on some code please? I've been staring at it so long I'm missing the obvious!

The code below is correctly finding items containing a particular text string, but it is not finding the associated first source and linked repository pointers (where these exist). No doubt it's the data reference that's the problem... and I will curse when an obvious problem is pointed out but I'm not too proud to ask!

Code: Select all


for ptrItem in allItems() do
    if TagSearch:Found(fhGetValueAsText(ptrItem), "#RN") == true then
    -- TagSearch is a search function (class) that is returning items correctly, some of which have sources, some of which have repositories
        local ptrS = nil
        local ptrR = nil
        ptrS = fhGetItemPtr(ptrItem, "~.SOUR")
        if ptrS:IsNull() then
            ptrS = nil
        else
            ptrR = fhGetItemPtr(ptrS,"~.REPO")
                if ptrR:IsNull() then ptrR = nil end
        end
        UpdateResults{ptrItem, ptrS, ptrR} --UpdateResults updates the plugin result tables
    end
end

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

Re: Obvious problem not staring me in the face

Post by Jane »

I would expect to find the "#RN" on a note field.

Are you expecting the Source on the Note or or on the Parent of the note?

Also are you wanting the link to the Source or the Source record ">"? You will need to go to the record to get the REPO
Jane
My Family History : My Photography "Knowledge is knowing that a tomato is a fruit. Wisdom is not putting it in a fruit salad."
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Obvious problem not staring me in the face

Post by ColeValleyGirl »

The #RN could be in any text field, including Fact note, Note record, Local note for an individual, Place note -- some of which can have sources, some of which (e.g. Place Note) can't.

I want to return a ptr item for the Source for the text field if one exists, and a ptr item for the Repository for that source.
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Obvious problem not staring me in the face

Post by tatewise »

Where do I begin?

Firstly, most text items referenced by ptrItem cannot have a Source Citation subsidiary tag (~.SOUR).
The only such text items would be Note fields.
So I suspect you need to move the ptrItem to its parent field that is more likely to allow ~.SOUR.
If it is a Fact Note do you want only Sources on that Note or also Sources on the Fact?

Secondly, ptrS and ptrR are pointers to the tags SOUR and REPO rather than the records they link to.
So as Jane says, ptrS = fhGetItemPtr(ptrItem, "~.SOUR>") will return the pointer to the linked Source record.
Then ptrR = fhGetItemPtr(ptrS,"~.REPO>") will return the pointer to the linked Repository record.
c.f.
ptrS = fhGetItemPtr(ptrItem, "~.SOUR")
ptrS = fhGetValueAsLink(ptrS)
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
User avatar
ColeValleyGirl
Megastar
Posts: 5465
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Obvious problem not staring me in the face

Post by ColeValleyGirl »

Mike, I only want the Sources for text items that have sources -- if the text item does not have a source (either because one isn't specified, or because one isn't allowed), I don't want its parent's source -- that isn't relevant.
User avatar
tatewise
Megastar
Posts: 28341
Joined: 25 May 2010 11:00
Family Historian: V7
Location: Torbay, Devon, UK
Contact:

Re: Obvious problem not staring me in the face

Post by tatewise »

OK, so Jane and my point about using > to find the record pointer rather than the tag pointer is your answer.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
Post Reply