* Would it be possible to rename a metafield

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
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Would it be possible to rename a metafield

Post by JoopvB » 09 Mar 2021 21:59

I am trying to find an easy way to change the source template of an existing source without ending up with undefined fields. By just changing the template link no data is lost. Fields with the same shortcut stay as they are. But the other ones end up as undefined and can only be retrieved through the all tab by hand (copy/paste). I am now trying to do it in a script, but after changing the template the old data is not accessible anymore (it says: [Undefined]: the data).

Some approaches I have tried/considered:
1. Saving all the values that need be moved and after changing the template link, enter them in the new fields.
2. Creating a new source and copy all fields and delete the old source.

Option 1 is complex because it has to provide for all field types. Option 2 seems like a kind of (too) brute force.
I hope a more easy option 3 exists. Ideas/solutions are highly appreciated.

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Would it be possible to rename a metafield

Post by ColeValleyGirl » 10 Mar 2021 08:33

I suspect it will have to be option 1... Have you looked at the code for pCite in fhUtils to get some ideas? (It's in C:\Program Files (x86)\Family Historian\Program\Lua)

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Would it be possible to rename a metafield

Post by ColeValleyGirl » 10 Mar 2021 09:53

P.S. Option 2 would lead you into all sorts of trouble with source links/citations...

User avatar
AdrianBruce
Megastar
Posts: 1962
Joined: 09 Aug 2003 21:02
Family Historian: V7
Location: South Cheshire
Contact:

Re: Would it be possible to rename a metafield

Post by AdrianBruce » 10 Mar 2021 11:36

From my position back in v6-land, I keep an eye on things that I might want to remember. This seems one - if I understand it correctly.

I can quite imagine me trying some new source records with a particular source-template - and then deciding that some of those would benefit from a different source-template. It might, for instance, include additional items to remind me what to enter. So - I'm trying to sort out what the pitfalls could be of assigning a new source-template to an existing source-record.

Would I be right in saying that additional items in the new source-template are not a problem as such (apart from being empty in the existing source-record)?

I guess that if I remove items from the new source-template (compared to the old), then the data is only accessible via the All Tab. Not sure why I'd remove items, mind you, since I'm thinking about refinements.

And if I "rename" items in the new source-template, then again, as stated above, I lose access to the old data apart from going via the All Tab. So, for instance, if I rename "Author" to "Transcriber" in the new template, then all my old Author data is made difficult to access.

The lesson then, should I try to create an amended source-template, is not to rename anything? And try to avoid deleting anything that might still contain useful info? I think.

Does this make sense?
Adrian

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Would it be possible to rename a metafield

Post by ColeValleyGirl » 10 Mar 2021 11:42

Adrian

One key thing is that, if you define your own custom templates, try to use the same names/types for metafields (for the same data).

Also, I think Joop is working on a 'changing the source template' plugin -- see the conversation at https://fhug.org.uk/forum/viewtopic.php ... 25#p111191

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

Re: Would it be possible to rename a metafield

Post by tatewise » 10 Mar 2021 12:00

Does the Tools > Source Template Definitions... dialogue Compare/Sync with Source Template Record... button provide a solution to any of the aforementioned issues?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

User avatar
ColeValleyGirl
Megastar
Posts: 4854
Joined: 28 Dec 2005 22:02
Family Historian: V7
Location: Cirencester, Gloucestershire
Contact:

Re: Would it be possible to rename a metafield

Post by ColeValleyGirl » 10 Mar 2021 12:03

Mike, how would you invoke it within a plugin?

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

Re: Would it be possible to rename a metafield

Post by tatewise » 10 Mar 2021 12:10

I was primarily thinking of Adrian's scenario, and maybe Joop could change the templates manually more easily than with a plugin, but certainly, that button is not available from within a Plugin. Maybe needs a new API function?
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry

avatar
JoopvB
Superstar
Posts: 328
Joined: 02 May 2015 14:32
Family Historian: V7

Re: Would it be possible to rename a metafield

Post by JoopvB » 10 Mar 2021 13:47

@Adrian
The first version of my plugin to change the source template of existing sources only changed the link to the template. The result is that all identical fields are available in the newly templated source and the ones that are not defined in the new template are only accessible via the all tab (as Undefined). So, as Helen suggests, the more identical fields the lesser the cleaning up afterwards.

However, I am in the process of modifying the plugin to map fields from the old template to the new as specified by the user (and allowed by field type). It will not create new fields, because I think the best way of doing this is through the Source template definition/sync tool (as Mike also mentions).

As soon as the plugin is usable I'll post it in this thread for testing.

User avatar
AdrianBruce
Megastar
Posts: 1962
Joined: 09 Aug 2003 21:02
Family Historian: V7
Location: South Cheshire
Contact:

Re: Would it be possible to rename a metafield

Post by AdrianBruce » 10 Mar 2021 15:20

ColeValleyGirl wrote:
10 Mar 2021 11:42
... if you define your own custom templates, try to use the same names/types for metafields (for the same data). ...
That makes sense - and summarises it nicely, thanks
Adrian

Post Reply