Page 1 of 1

Using custom IDs

Posted: 02 Nov 2013 13:53
by TeaSeaPea
I have not attempted creating a "Plug In" before so very much need your help.

I am a coordinating a one name study and have a heavy reliance on the Custom ID field to allocate unique references that can be alpha numeric in construction. These are allocated to individuals.

The problem that I have encountered is the inability to generate a descendants report where Custom IDs are identified against an individual.

I have been informed that writing a PlugIn may resolve this.

Any help would be appreciated.

Best regards

Trevor

Re: Using custom IDs

Posted: 02 Nov 2013 16:48
by tatewise
Hello Trevor, the general plan is as follows:
  1. You create a Custom Attribute Fact to hold the Individual Custom Id as its value.
  2. Set its Sentence Template appropriately for the Narrative Reports.
  3. Set its Normal Time Frame to position the Custom Attribute among other Facts.
  4. Run a Plugin to copy each Individual Custom Id to its Custom Attribute Fact value.
1. Create Custom Attribute Fact
Use Tools > Work With Fact Sets > New with Fact Name = Custom Id and Fact Type = Attribute and Record Type = Individual.
Either leave Fact Set = Custom or perhaps set it to Custom Id and click Create.
You may wish to disable some Fields Required such as Age and Place and Address.
(If you choose a different Fact Name than Custom Id then the Plugin text "Custom Id" must be changed likewise.)

2. Set the Sentence Template
Something like {label} = {value} will produce Cutom Id = ABC123. in Reports.
This can be adjusted later to produce just what you want.

3. Set the Normal Time Frame
Set this to Pre-Birth to come first, or Post-Death to come last, among other Facts.
This can be adjusted later to position it just where you want, or you can add a Date to the Attribute to position it among other Facts.

4. The Plugin
To create the Plugin use Tools > Plugins > More>> > New and copy & paste the code below into the editor.
Use File > Save As > Plugin Name = Copy Custom Id To Attribute.
Then close the editor, select the Plugin name and tick Add to Tools Menu.
To run the Plugin use Tools > Copy Custom Id To Attribute and repeat whenever Custom Id Attributes need updating.

One word of caution: Every Individual Record that requires a new Custom Id Attribute, will have its Updated date - updated!

The following code should do the job:

Code: Select all

--[[
@Title:			Copy Custom Id To Attribute
@Author:			Mike Tate
@Version:			1.0
@LastUpdated:	02 Nov 2013
@Description:	Copy every Individual Custom Id to a Fact Attribute Value.
]]
	-- Determine the Custom Id Attribute Fact Tag
	local strFactTag, strError = fhGetFactTag("Custom Id", "Attribute", "INDI", true)
	if strError ~= nil then
		error("Error Creating Custom Id Attribute Tag\n"..strError)
	end
	local ptrIndi = fhNewItemPtr()
	ptrIndi:MoveToFirstRecord("INDI")
	while ptrIndi:IsNotNull() do									-- Loop through Individual Records
		ptrRefn = fhGetItemPtr(ptrIndi,"~.REFN")
		strRefn = fhGetValueAsText(ptrRefn)						-- Get the Custom Id value
		ptrAttr = fhGetItemPtr(ptrIndi,"~."..strFactTag)
		strAttr = fhGetValueAsText(ptrAttr)						-- Get the Custom Id Attribute value
		if strRefn ~= strAttr then								-- Custom Id equals Attribute?
			if ptrAttr:IsNull() then
				ptrAttr = fhCreateItem(strFactTag,ptrIndi)	-- Create new Custom Id Attribute Fact
				if ptrAttr:IsNull() then
					fhMessageBox("Error creating Custom Id : '"..strRefn.."' Attribute for "..fhGetDisplayText(ptrIndi))
					return
				end
			end
			fhSetValueAsText(ptrAttr,strRefn)					-- Save new Custom Id Attribute value
		end
	   ptrIndi:MoveNext()
	end

Re: Using custom IDs

Posted: 04 Nov 2013 10:21
by TeaSeaPea
Mike,

Thank you very much.

I will give this a go when I get back from holiday.

Best regards

Trevor