def try_add_realm_custom_profile_field(realm: Realm, name: str, field_type: int, hint: str='', field_data: Optional[ProfileFieldData]=None) -> CustomProfileField:
    field = CustomProfileField(realm=realm, name=name, field_type=field_type)
    field.hint = hint
    if ((field.field_type == CustomProfileField.CHOICE) or (field.field_type == CustomProfileField.EXTERNAL_ACCOUNT)):
        field.field_data = ujson.dumps((field_data or {}))
    field.save()
    field.order = field.id
    field.save(update_fields=['order'])
    notify_realm_custom_profile_fields(realm, 'add')
    return field
def try_add_realm_custom_profile_field(realm: Realm, name: str, field_type: int, hint: str=, field_data: Optional[ProfileFieldData]=None) -> CustomProfileField:
    field = CustomProfileField(realm=realm, name=name, field_type=field_type)
    field.hint = hint
    if ((field.field_type == CustomProfileField.CHOICE) or (field.field_type == CustomProfileField.EXTERNAL_ACCOUNT)):
        field.field_data = ujson.dumps((field_data or {}))
    field.save()
    field.order = field.id
    field.save(update_fields=['order'])
    notify_realm_custom_profile_fields(realm, 'add')
    return field