MM5.6 BSI Pardot crops automation

Background

BSI use Pardot for emails. They want the images for these emails to come from their DAM. They need to be the correct size, when they come out of the DAM. BSI have 12 crop presets that match the sizes Pardot uses.

Prior to 5.3, when only aspect ratio cropping was available, they had to crop, then click through to the cropped asset and choose the correct size from a tree, to generate the URL (and publish that format to the non secure folder). Now that crop and resize in one step is available, they can use the ‘original’ instead of a specific format, because the original will be the cropped and resized asset.

As they will only ever crop for Pardot, the Pardot link will always be required, so they want it automatically generated on all crops. They also want to know the size of the crop before clicking through to it. Before cropping to a particular size, they want to find all other assets that have already been cropped to that size so they can reuse one of those, instead of creating a new crop, if possible.

The flow

A search/automation combination has been set up to:

  1. Check if a new asset is a crop

  2. Clear fields that should not be copied from parent

  3. Retrieve the asset width and height

  4. Tick the Pardot Link? field

  5. Prepend the width and height to the title

  6. Add the new crop size to the Cropped Sizes field on the parent

Search

To generate the Pardot link for crops only, the automation needs to determine if an asset it a crop or not. This is in part done by checking the Prevref of the asset. The following search has been added:

  • Name: GetPrevref

  • Input: Asset ID ID: sAssetId

  • Output:

    • Prevref (from asset table) ID: sPrevref Return Type: Int

    • image_width (from asset table) ID: width

    • image_height (from asset table) ID: height

Automation

trigger "Asset Added to MM Admin Layout Folder" { type = "Asset Folder Updated Trigger" resolves = ["Set Pardot Link Bit", "Prepend Size to Title", "Set Cropped Sizes on Parent"] to_folder = "10,126" } filter "Image Only" { type = "Asset type filter" asset_type = "image" asset_id = "@sourceAssetId" negate = "false" needs = [] } action "Search" { type = "Search" needs = "Image Only" search = "GetPrevref" search_parameters = "(sAssetId),(@sourceAssetId)" result = "@PrevRef" } action "Query JSON Prevref" { type = "Query JSON" needs = "Search" json = "@PrevRef" json_path = "$[0].sPrevref" error_on_not_found_items = "false" result = "@PrevRefFinal" } filter "Prevref Not 0" { type = "Int Compare filter" needs = "Query JSON Prevref" value = "@PrevRefFinal" compare_with = "0" comparison_method = "equals" negate = "true" } action "Clear Pardot Link Bit" { type = "Clear metafield" needs = "Prevref Not 0" asset_item_id = "@sourceAssetItemId" metafield = "guid:1B0C2BC9-D7B8-4CAC-A09B-D192214F8C05" } action "Clear Cropped Sizes field" { type = "Clear metafield" needs = "Clear Pardot Link Bit" asset_item_id = "@sourceAssetItemId" metafield = "guid:12AD524A-29EE-4413-A238-80E2BD2016FC" } action "Set Pardot Link Bit" { type = "Set Bit Metafield" needs = ["Clear Pardot Link Bit", "Clear Cropped Sizes field"] meta_field = "guid:1B0C2BC9-D7B8-4CAC-A09B-D192214F8C05" new_value = "true" asset_item_id = "@sourceAssetItemId" use_versioned_metadata = "false" } action "Query JSON Width" { type = "Query JSON" needs = "Prevref Not 0" json = "@PrevRef" json_path = "$[0].width" error_on_not_found_items = "false" result = "@assetWidth" } action "Query JSON Height" { type = "Query JSON" needs = "Query JSON Width" json = "@PrevRef" json_path = "$[0].height" error_on_not_found_items = "false" result = "@assetHeight" } filter "Retrieve Asset Title" { type = "Retrieve metadata value for string metafield" needs = "Query JSON Height" item_id = "@sourceAssetItemId" meta_field = "guid:5EB3EEFC-A043-410F-89B0-29ED3EF37078" value = "@assetTitle" negate = "false" } action "Prepend Size to Title" { type = "Set String Metafield" needs = "Retrieve Asset Title" meta_field = "guid:5EB3EEFC-A043-410F-89B0-29ED3EF37078" new_value = "@assetWidth x @assetHeight @assetTitle" asset_item_id = "@sourceAssetItemId" use_versioned_metadata = "false" } action "Get Parent Item ID from Prevref" { type = "Convert Asset Id To Asset Item Id" needs = "Retrieve Asset Title" asset_id = "@PrevRefFinal" asset_item_id = "@ParentItemID" } action "Set Cropped Sizes on Parent" { type = "Set EditMultiComboValue Metafield" needs = "Get Parent Item ID from Prevref" update_method = "merge" meta_field = "guid:12AD524A-29EE-4413-A238-80E2BD2016FC" new_value = [] asset_item_id = "@ParentItemID" use_versioned_metadata = "false" }

The automation is triggered by an asset being added to the MM admin access layout folder

 

 

Using another trigger (e.g asset created) could trigger for replaced assets as well. The process and explanation that happens after an asset is added to the MM admin access folder is below:

  1. Asset type image filter (because only images can be cropped)

  2. Run GetPrevref search (to retrieve the prevref, width and height for later steps)

  3. Use JSON to get the prevref from the search results

  4. Check if the prevref is NOT 0 (it will be 0 for new assets and replacements by time they get added to the folder, so if it is not 0, image must be a crop)

  5. Clear the Pardot Link? bit (just in case the value has been copied from the parent)

  6. Clear the Cropped Sizes field (it is only relevant for the parent asset)

  7. Set the Pardot Link? bit to true (to trigger the Pardot Distribution workflow)

  8. Use JSON to get the width and height from the search results

  9. Retrieve the asset title from the metadata (to add it in the next step)

  10. Write the width, height and asset title to the title field. (Prepends crop size to title, so it is easy to know the crop size when viewing them in the Related Assets tab)

  11. Converts the parent asset ID (Prevref) to an item ID (to update the parent in the next step)

  12. Adds the cropped size to the list of Cropped sizes in the parent. (To make it possible to search for cropped assets by size).