Part of building out my Marvel Snap clone involved finding a source for the Card data. As mentioned earlier, I found a great database of cards that had an API that I could use to get the card records. The next thing I needed to do was import the images themselves. I created an Image field on the Card Definition record, but I needed to bring the images in via an automated method.
Looking at the card database website, I found that the images were stored in a folder:
https://images.marvelsnap.io/images/cards
Each image was stored as a .webp file. This doesn’t help me, because the image field type doesn’t support webp files… Luckily the database I was grabbing my cards from also had a JPG version in the same folder – very handy! The filenames were in the format <id>.jpg, so all I needed to do was substitute the card ID in the REST URL path to find the right file.
Using a Flow Designer action with a REST Step I could perform a GET on the URL of the JPG file:

Flow Designer lets you save the payload as an attachment, and asks for a record and file name to write to the attachment table. In order to make an attachment in the attachment table map to a specific field (like an attachment or image field) we need to set the file name to match the field name.

Technically if you attached file by hand to the image field, in the sys_attachment table for image files ServiceNow will prepend ZZ_YY to the table name (Which effectively stops the file from appearing in the “Attachment” section of the record, but this isn’t a dealbreaker for this implementation. If I was more worried about being clean with my implementation, I’d go in to the attachment record after the fact and rename the table_name field.

Adding this Subflow to my existing card definition Subflow gives me a nice little “Get the card Definition, then add the image” automation:

Here’s what the cards are starting to look like in my definition database:

Next few things I think I’ll need to do:
– Start looking at what it will take to select my player’s deck from my definition files (for example a Marvel Snap deck has 12 cards in it – how do we keep track of the number of cards in a deck?)
– Work on a shuffling/randomiser system for creating the active card instances for the player’s deck
– Work on another card import for the Location cards (I might refactor my character card import mechanism so that it does two passes – one for location and one for character – right now it’s hard-coded to character only)
– Work on my “Game initialisation” flow – I’ll need to start a game session, shuffle the locations into the right positions and shuffle each player’s deck into card instances
– Work on all the flows for different player events (with decisions and dynamic subflows to execute the card subflows)
– Start creating ALL the subflows for each card (and probably a big library of subflows for different reusable behaviours).

Leave a Reply