Page 1 of 1

Attach a Flag to an Individual

Posted: 11 Sep 2013 19:53
by mikej
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

Re: Attach a Flag to an Individual

Posted: 11 Sep 2013 21:35
by tatewise
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.

Re: Attach a Flag to an Individual

Posted: 12 Sep 2013 09:24
by Jane
I have added Mike's example to the code snippets with a few changes
plugins:code_snippets:flags_add_and_remove_function|setFlag Function

Re: Attach a Flag to an Individual

Posted: 12 Sep 2013 09:34
by mikej
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