Page 1 of 1

Existence of a field definition in Source Template

Posted: 22 Jun 2023 10:05
by Medows
Hello,
I apologise if I have already asked this but VirginMedia have loats all my emails and therefore questions I have asked in FHUG.
I am looking to check for the existence of 2 common field definitions I have in my Source Templates. Yes I could go through them one at a time but I was looking for a more automated way.
In each of my templates I have 2 defintions - Research Date, Research Place. I have found one where I put the Resaerch Place before the Research Date and I think there may be one or two where I have not put these in at all. I use them for my personal use to know when and where I have been on my travels.

A source template of course has a variable number of Field Definitions (FDEF) which means I can't put in a code such as...
%_SRCT.FDEF[2]% - because this is the second field within that template.

So I would like to know the following...
Template name, Collection, position of "Reseach Date", position of "Research Place, number of links and possibly the type of field the research date and reseach place.

When writing templates I strive for consistency but there are 3 of us (myself, wife and daughter) creating these templates but we do keep a master copy between us.

Is what I am asking for possible?

Alan

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 10:35
by ColeValleyGirl
The Help File section on Data References And Metafields (scroll down) give ypu the information ypu need to reference the metafields via their names and not their position.

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 10:45
by tatewise
Helen, I don't think that provides the position of a metafield and does not work in Source Templates only in Source records.

Yes, Alan, I think you can achieve most if not all your requirements.

Focus on the Records Window, Source Templates tab which by default lists Template Name, Collection, and Links, etc.

To determine the position and existence of a metafield definition needs a nested set of TextIf(...) functions.

Use Lists > Configure Record Window Columns... or right-click the heading and choose Configure Columns...
In the Configure Columns dialogue select <Other...> and add > to Columns on right.
In the Heading enter the Name of your field Research Date.
In the Expression enter the following:
=TextIf(%_SRCT.FDEF.NAME% = "Research Date","1", TextIf(%_SRCT.FDEF[2].NAME% = "Research Date","2", TextIf(%_SRCT.FDEF[3].NAME% = "Research Date","3", TextIf(%_SRCT.FDEF[4].NAME% = "Research Date","4", "?"))))
If its position may be beyond the 4th field definition then more nested TextIf(...) functions are needed.
If you know its lowest position then some of the earlier TextIf(...) functions are not needed.

Repeat the whole process for Research Place. The easiest way is to copy the Expression into a plain text editor, use Find & Replace to change the word Date to Place and paste it into the new Expression.

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 10:45
by Mark1834
Two options:

Create a new custom query of type Source Template, and list each field definition in sequence. You can then either inspect manually or export the results to file.

Alternatively, inspect the definition file directly, which is stored at C:\ProgramData\Calico Pie\Family Historian\Source Templates\Custom, with one file for each collection. If you open the collection file with a text editor (Notepad is fine), you can use the usual text search function to locate names of interest. It does not give the position explicitly, but fields are listed in order for each template.

Be careful not to change the file, so it is probably safer to create a copy first and work from that.

edit - posted simultaneously with Mike, but I think my version is a lot less typing :)

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 16:18
by Medows
Thank you everybody for your suggestions. I eventually used Mike's solution as it was more automatic especially after initial setup.

Alan

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 17:22
by Mark1834
No problem, but make sure that you understand exactly what the functions are doing rather than just copying them blindly, as you will then be able to use and adapt them for other similar scenarios in the future.

Re: Existence of a field definition in Source Template

Posted: 22 Jun 2023 17:34
by Medows
Thanks for that remark. I do understand them.