handlers.link_fact_sheet_by_subscription_handler

class LinkFactSheetBySubscriptionHandler(handlers.eventhandler.EventHandler):

Example use case: If an Application Owner is added or removed from an Application, this automation looks up the Organization of the subscribed user and links it as owning Organization (usageType: owner).

Generic logic: We configure a mapping of roles and usageTypes, like this:
"Application Owner": "owner", "Component Manager": "componentOwner", and also a means to identify the corresponding fact sheet: "user_field_source": "userProperty" or "lansweeper" or "entraID" (to be implemented) "user_field": "Department", "linked_fs_type": "Organization", "match_field": "shortName" "role_field": "usageType" The automation will then monitor all subscription events (added/removed/updated), look up the correct fact sheet, unlink any previously-linked fact sheets of this usage type and link all fact sheets that need to be linked, or update the usage type if the fact sheet is already linked.

To specify what happens if a user is unsubscribed, you can use the following options: "deletion_action": "delete_relation" or "delete_usage_type"

LinkFactSheetBySubscriptionHandler(config, **kwargs)
name = 'Link Fact Sheets by Subscription'
description = 'Looks up and links or unlinks a fact sheet whenever a user in a specific role is subscribed / unsubscribed.'
conditions = {'event_types': ['SubscriptionCreatedEvent', 'SubscriptionDeletedEvent', 'SubscriptionUpdatedEvent']}
supports_initial_sync = True
config_template = {'fs_types': ['Application', 'ITComponent', 'Interface'], 'role_mapping': {'Application': {'Application Owner': 'applicationOwnership', 'Component Manager': 'componentOwnership', '__ALL__': 'applicationAndComponentOwnership'}, 'ITComponent': {'Component Manager': 'owner'}, 'Interface': {'Interface Manager': 'owner'}}, 'user_field_source': 'lansweeper', 'user_field': 'department', 'linked_fs_type': 'Organization', 'linked_fs_relations': {'Application': 'relApplicationToOrganization', 'ITComponent': 'relITComponentToOrganization', 'Interface': 'relInterfaceToOrganization'}, 'match_field': 'shortName', 'role_field': 'usageType', 'deletion_action': 'delete_usage_type'}
def handle(self, event, fs, **kwargs):

Called automatically whenever a FactSheetUpdated event comes in via webhook.