Scripted creation of asset catalog and custom fields

Hello,

We’re currently evaluating RT’s Asset module as a potential way of tracking equipment, both fixed and movable. To easily move from testing to production, I’d like to script as much as possible in terms of the setup, and I was hoping somebody could give me a hint on how to create certain types of objects.

Ideally I’d use the serialized JSON data approach, but that seems to be still in development, so instead I’m using customizing/assets/tutorialdata as a starting point.

  1. How does one create a new catalog? Even better, how does one create it only if specific name doesn’t exist?

  2. How does one create a custom field and apply it to more than one catalog at the time? I was trying the following approach, but that applies only to the first catalog

@CustomFields = (
    {   Name       => 'Custodian ID',
        Type       => 'FreeformSingle',
        LookupType => 'RT::Catalog-RT::Asset',
        ApplyTo    => 'Fixed equipment', 'Movable equipment',
    },

);
  1. How does one create said custom field only if it doesn’t exist already? Re-running the above will result in duplicate fields. A workaround for question #2 could be by only applying the mapping between custom fields and catalogs, without recreating them.

Thanks!

Looks like for ApplyTo an array can be used. For example:

@CustomFields = (
    {   Name       => 'ABC123',
        Type       => 'FreeformSingle',
        LookupType => 'RT::Catalog-RT::Asset',
        ApplyTo    => [ 'Fixed equipment', 'Hardware' ],
    },

);