Media – Set Primary Photo for Persons #media #update

This query responds to a problem with an import from Family Historian via FTM-flavoured GEDCOM reported by Stewartrb in the RootsMagic Forums thread
GEDCOM import with media. The images linked to the person in Family Historian were ultimately tagged as such in RootsMagic but none was marked as the Primary photo. Consequently, none showed on the main screen nor in reports other than Scrapbooks. This query sets the last image-type media file added to the Gallery among those that have been tagged to a person as that person’s Primary photo, when none of the tags for that person have been so checked. It could be readily modified to be the last tag added to the person rather than the last imported mediafile or to be the first instead of the last.

MediaTags-SetPrimaryForPersons.sql

MediaTags-SetPrimaryForPersons-FirstTag.sql Added 2025-04-18 Sets the first mediatag as the Primary.
Both versions are compatible with RM4 to #RM10.

-- MediaTags-SetPrimaryForPersons.sql
/* 2013-09-23 ve3meo
Sets the last mediatag as the Primary photo for a person with 1 or more tags for image-type media, none of which are so checked.
*/
UPDATE MediaLinkTable
SET    IsPrimary = 1
WHERE  LinkID IN
       ( -- a list of the last LinkIDs for persons with image-type media tags, none of which marked as the Primary photo
       SELECT  LinkID
       FROM    ( SELECT  *
               FROM     ( SELECT    ML.LinkID        -- tag number
                                 , ML.OwnerID        -- RIN for person, given the constraint below
                                 , ML.IsPrimary      -- 1 if tag box checked "Primary photo for this person" else 0
                        FROM       MediaLinkTable ML -- media tags table
                                   INNER JOIN MultiMediaTable MM
                        USING      (MediaID)        -- mediafiles table
                        WHERE      ML.OwnerType = 0 -- person
                        AND        MM.MediaType = 1 -- image type
                        ORDER BY   ML.OwnerID       -- sort by ownerid then
                                 , ML.IsPrimary     -- isprimary, putting any tag for the person set as primary to the bottom of the list
                        )
               GROUP BY OwnerID -- only the last LinkID in the list for the person comes out
               )
       WHERE   NOT IsPrimary -- only the last LinkID for a person with tags, none marked primary
       );

3 Replies to “Media – Set Primary Photo for Persons #media #update

  1. On the RM Community page, I posted the following on a page where users are discussing problems with TreeShare. https://community.rootsmagic.com/t/reset-treeshare-tool/13315
    I am following all of this with great interest. Basically I had a large tree over 500,000 people that had been linked to treeshare for several years. For reasons I can’t remember, I decided to disconnect my tree and re-upload it. I wish I had never done this. I have not successfully uploaded the tree; it gets stuck while uploading media … sometimes early, sometimes at 99%. I have not gotten past that poinr so unsure if I have a similar problem with sources. However I noticed one thing that no one else has mentioned. I ran Media – Set Primary Photo for Persons #media #update several months ago and just noticed that some people have multiple media checked as primary photos. Hmmmm….. If I remove all the checks and attempt to check multiples, RM does not allow it, as it should. I am wondering if this might be the reason my tree freezes during the media upload? Does anyone else have multiple pictures checked as primary? I am going to copy/paste this post onto the SQLite Tools for RM page. Maybe all I need is a new script to uncheck all media.

  2. I just saw your comment here but your link to the RootsMagic Community topic on Resetting TreeShare has no comment from you. If you want to unset all Primary images for a Person, this should work:
    UPDATE MediaLinkTable
    SET IsPrimary = 0
    WHERE
    OwnerType=0
    ;
    Remove the WHERE clause to eliminate any other Primary settings for all types of media and for all tags, not just to Persons.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.