* Attach a Flag to an Individual

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
mikej
Gold
Posts: 12
Joined: 07 Jun 2011 10:06
Family Historian: V7
Location: Wales

Attach a Flag to an Individual

Post by mikej » 11 Sep 2013 19:53

I am trying to attach a NoParents Flag to an individual but am having some difficulty.
I can create the Flag by using:

strNewFlag='NoParents'
strTag, strError = fhGetFlagTag(strNewFlag,true)

but I cannot work out how to assign the flag to an individual.

I have searched this Forum and the Help file without success.
Also I cannot find anything in the samples or the Plugin store to help.
I would appreciate a nudge in the right direction please.

tia

Mike
Regards
MikeJ

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

Re: Attach a Flag to an Individual

Post by tatewise » 11 Sep 2013 21:35

Here is a snippet of code to add a Flag:

Code: Select all

local ptrRec = fhNewItemPtr()                       -- Obtain an Individual Record pointer for demo
ptrRec:MoveToFirstRecord("INDI")
strTag, strError = fhGetFlagTag("NoParent", true)   -- Obtain tag for "NoParent" Flag
ptrFlgs = fhGetItemPtr(ptrRec, "~._FLGS")           -- Check "_FLGS" tag
if ptrFlgs:IsNull() then 
   ptrFlgs = fhCreateItem("_FLGS", ptrRec)          -- Create "_FLGS" tag if necessary
end
ptrFlag = fhCreateItem(strTag, ptrFlgs)             -- Create the "NoParent" Flag
This does not have any IsNull() checks to ensure created items are successful, nor if the "NoParent" Flag already exists.
I leave that for you to develop.

However, this begs the question ~ Why do you want to set NoParent Flags?
The expression =Exists(%INDI.FAMC[1]%) essentially does the same job more efficiently, and automatically is correct without having to manually run a Plugin or Query to set Flags.
This expression can be used to condition a Records Window Column, or a Diagram Icon, or a Query filter, etc, etc.
See how_to:using_flags_and_icons|: Using Flags and Icons for much more detail.
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

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

Re: Attach a Flag to an Individual

Post by Jane » 12 Sep 2013 09:24

I have added Mike's example to the code snippets with a few changes
plugins:code_snippets:flags_add_and_remove_function|setFlag Function
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
mikej
Gold
Posts: 12
Joined: 07 Jun 2011 10:06
Family Historian: V7
Location: Wales

Re: Attach a Flag to an Individual

Post by mikej » 12 Sep 2013 09:34

Mike
Thank you very much for the info. That worked perfectly!
I can see where I was going wrong now. I was trying to create the "NoParent" flag without first creating the "_FLGS" tag.

Re your question as to why.
I wish to set the flag as part of my Census csv import plugin. Setting a flag when a combination of circumstances occurs will highlight the need for closer inspection after import.
In this instance when a Son or Daughter (relation to hoh in census) is imported without a Parent having been assigned to them.

Thanks once again.

MikeJ

Post Reply