* Handling Fact Flags in a plugin

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
quarlton
Famous
Posts: 150
Joined: 26 Feb 2004 13:07
Family Historian: V7
Location: Lincolnshire
Contact:

Handling Fact Flags in a plugin

Post by quarlton » 08 Aug 2023 15:14

I'm writing a plugin to set the 'Preferred' flag on all BIRT events.
[This relates to https://groups.io/g/family-historian/message/7112 - Highlight or Colour Facts on the property box]
Following Mike's code above I can check if the flag already exists, so skip to next INDI.
I can create the tag OK, but can't work out how to set the value.

Code: Select all

--Create a Flag tag on the BIRT
--ptrFlag2 is a pointer to the BIRT event
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2)  -- This works fine and creates the tag
fhSetValueAsText(ptrFlagNew, "Preferred")           -- This fails
I've searched the FH plugin guide and this forum but can't find the right syntax.
Any help would be much appreciated
Dave Simpson ~ Boulton, Braham, Carney, Simpson and Jacobs

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

Re: Handling Fact Flags in a plugin

Post by tatewise » 08 Aug 2023 15:58

Dave, I have started a new thread because the Handling Custom Flags in a plugin (17518) thread you used focuses on Individual Record Flags not Fact Flags.

As I often suggest, the way to discover FH/GEDCOM codes is to use any FH Data Reference Assistant as follows.
Open the Query > Relatives and Relationships > All Individuals and open the Columns tab.
Below the box below the Fields, use the small triangular button to Show Both in Box.
Then in Fields, choose Events + Birth + Flags + Preferred to reveal Preferred fact flag %INDI.BIRT[1]._FLGS.__PREFERRED%

I'm unsure whether "__PREFERRED" is set as a text value or must be created just like the "_FLGS" tag (I suspect the latter).

BTW: Make sure you are actually checking the BIRT event and remember that any combination of Fact Flags can be set.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
quarlton
Famous
Posts: 150
Joined: 26 Feb 2004 13:07
Family Historian: V7
Location: Lincolnshire
Contact:

Re: Handling Fact Flags in a plugin

Post by quarlton » 08 Aug 2023 16:53

Thanks for that Mike.

Unfortunately I haven't managed to find the correct syntax for setting the value for the tag.

I'll persevere and see what I can come up with.
Dave Simpson ~ Boulton, Braham, Carney, Simpson and Jacobs

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

Re: Handling Fact Flags in a plugin

Post by tatewise » 08 Aug 2023 17:38

The syntax is the same as you are already using:
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2)

But the item you're creating is "__PREFERRED" and the parent is ptrFlagNew.

Are you sure that ptrFlag2 is pointing to a BIRT event tag?

Try stepping through the plugin script in the debugger one line at a time by setting a breakpoint in the lefthand margin.
If ptrFlag2 is pointing to a BIRT event then the birth details should be shown as its Value in lower right pane.

If you really cannot get it to work then post your entire script here.
I could post a solution, but learning debug techniques are a good exercise.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
quarlton
Famous
Posts: 150
Joined: 26 Feb 2004 13:07
Family Historian: V7
Location: Lincolnshire
Contact:

Re: Handling Fact Flags in a plugin

Post by quarlton » 08 Aug 2023 20:00

Hi Mike

Thanks for that, it works a treat

Code: Select all

--Create a Flag tag on the BIRT
--ptrFlag2 is a pointer to the BIRT event
local ptrFlagNew = fhCreateItem("_FLGS", ptrFlag2)          -- This creates the tag
local ptrFlagNew2 = fhCreateItem("__PREFERRED", ptrFlagNew) -- This sets the value
Regards
Dave Simpson ~ Boulton, Braham, Carney, Simpson and Jacobs

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

Re: Handling Fact Flags in a plugin

Post by tatewise » 08 Aug 2023 20:31

FYI: The final script I came up with is as below and checks every Birth Event for every Individual.
It caters for multiple Birth Events for one Individual and checks before adding the Preferred Flag to each one.
It could be extended to cater for other key Individual events, but needs an alternative method for Family events like Marriage.
It is left to the reader to make those amendments...

Code: Select all

local ptrIndi = fhNewItemPtr()
ptrIndi:MoveToFirstRecord("INDI")
while ptrIndi:IsNotNull() do					-- Check each Individual
	local ptrBirt = fhGetItemPtr(ptrIndi,"~.BIRT")
	while ptrBirt:IsNotNull() do				-- Check each Birth Event
		local ptrFlag = fhGetItemPtr(ptrBirt,"~._FLGS") 
		if ptrFlag:IsNull() then			-- Ensure the Fact Flags tag exists
			ptrFlag = fhCreateItem("_FLGS", ptrBirt)
		end
		if ptrFlag:IsNotNull() then			-- Check if Preferred Flag exists
			local ptrPref = fhGetItemPtr(ptrFlag,"~.__PREFERRED")
			if ptrPref:IsNull() then		-- Ensure Preferred Flag is added
				ptrPref = fhCreateItem("__PREFERRED", ptrFlag)
			end
		end
		ptrBirt:MoveNext("SAME_TAG")
	end
	ptrIndi:MoveNext()
end
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

Post Reply