PreferenceDestination - 범위 지정, 전역

  • 릴리스 버전: Yokohama
  • 업데이트 날짜 2025년 01월 30일
  • 읽기9분
  • PreferenceDestination API는 사용자 알림 기본 설정을 업데이트합니다.

    알림 대상은 특정 이메일 주소나 전화 번호와 같이 알림을 전달할 수 있는 위치입니다. 이 API는 알림 [sys_notification] 테이블의 알림을 기반으로 합니다. 알림은 이메일 또는 작업 공간와 같은 채널을 통해 전송됩니다. 채널을 사용하여 여러 유형의 대상에 알림을 보낼 수 있습니다. 예를 들어 이메일 채널은 개인 이메일과 회사 이메일 대상 모두에 알림을 보낼 수 있습니다. 대상 유형은 알림 대상 유형 [sys_notif_destination_type] 테이블에 나열됩니다.

    사용자는 자신의 알림 기본 설정을 업데이트할 수 있으며, 관리자는 모든 사용자의 알림 기본 설정을 업데이트할 수 있습니다. 사용자 알림 기본 설정은 알림을 수신할 대상을 제어합니다.

    기본 설정 API와 함께 이 API를 사용합니다. 이 클래스의 메서드를 호출하기 전에 Preferences.getDestinations() 또는 Preferences.getDestinationsByChannel() 메서드를 호출하여 PreferenceDestination 객체를 인스턴스화해야 합니다.

    이 클래스는 sn_notification 네임스페이스 식별자를 사용합니다.

    PreferenceDestination - getChannel()

    대상으로 알림을 보내는 데 사용되는 채널을 반환합니다.

    표 1. 매개변수
    이름 유형 설명
    없음
    표 2. 반환
    유형 설명
    GlideRecord 대상에 알림을 보내는 데 사용되는 채널에 대한 알림 채널 [sys_notification_channel] 테이블의 GlideRecord입니다.

    이 예에서는 Abel Tuter의 각 대상에 대한 알림을 보내는 데 사용되는 채널을 인쇄합니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    for (var i=0; i<dests.length; i++) {
         gs.print('Channel for destination '+(i+1)+' is '+dests[i].getChannel().name); 
    }

    출력:

    Channel for destination 1 is Workspace

    PreferenceDestination - getDeliverTo()

    대상의 식별자를 반환합니다.

    표 3. 매개변수
    이름 유형 설명
    없음
    표 4. 반환
    유형 설명
    문자열 대상의 식별자입니다. 예를 들면 이메일 주소, 푸시 애플리케이션 설치 토큰 또는 sys_id입니다.

    이 예제에서는 Abel Tuter의 각 대상에 대한 식별자를 인쇄합니다. 출력은 Abel 작업 공간 대상의 식별자가 사용자 sys_id임을 보여줍니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    for (var i=0; i<dests.length; i++) {
         gs.print('The identifier for '+recipient.first_name+'\'s '+dests[i].getDestinationType().name+' destination is '+dests[i].getDeliverTo());
    }

    출력:

    The identifier for Abel's Workspace destination is 62826bf03710200044e0bfc8bcbe5df1

    PreferenceDestination - getDestinationType()

    개인 이메일 또는 회사 이메일과 같은 대상 유형을 반환합니다.

    표 5. 매개변수
    이름 유형 설명
    없음
    표 6. 반환
    유형 설명
    GlideRecord 대상 유형에 대한 알림 대상 유형 [sys_notif_destination_type] 테이블의 GlideRecord

    이 예제에서는 Abel Tuter의 각 대상에 대한 식별자를 인쇄합니다. 출력은 Abel 작업 공간 대상의 식별자가 사용자 sys_id임을 보여줍니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    for (var i=0; i<dests.length; i++) {
         gs.print('The identifier for '+recipient.first_name+'\'s '+dests[i].getDestinationType().name+' destination is '+dests[i].getDeliverTo());
    }

    출력:

    The identifier for Abel's Workspace destination is 62826bf03710200044e0bfc8bcbe5df1

    PreferenceDestination - isActive(GlideRecord 알림)

    대상에 알림을 받을 수 있는 권한이 있는지 확인합니다.

    표 7. 매개변수
    이름 유형 설명
    알림 GlideRecord 옵션입니다. 대상에 해당 알림을 받을 수 있는 권한이 있는지 확인하는 알림입니다. 알림이 없거나 대상의 사용자가 알림을 읽을 수 없는 경우 예외가 throw됩니다. 알림이 지정되지 않은 경우 이 메서드는 대상에 알림을 받을 수 있는 권한이 있는지 확인합니다.
    표 8. 반환
    유형 설명
    부울 대상에 알림을 받을 수 있는 권한이 있는지 여부를 나타내는 플래그입니다.
    가능한 값:
    • true: 대상에 알림 수신 권한이 있습니다.
    • false: 대상에 알림을 받을 수 있는 권한이 없습니다.

    이 예제에서는 Abel Tuter의 각 대상에 승인 요청 알림을 받을 수 있는 권한이 있는지 확인합니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    var notif = new GlideRecord('sys_notification'); 
    notif.get('name', 'Approval Request'); 
    for (var i=0; i<dests.length; i++) {
       var active = dests[i].isActive(notif) ? 'active' : 'inactive'; 
       gs.print(dests[i].getDestinationType().name + ' ' + dests[i].getDeliverTo() + ' is ' + active + ' for this notification');
    }

    출력:

    Workspace 62826bf03710200044e0bfc8bcbe5df1 is active for this notification

    PreferenceDestination - isOverriden(GlideRecord 알림)

    알림이 대상에 대한 사용자의 기본 설정을 재정의하는지 확인합니다.

    표 9. 매개변수
    이름 유형 설명
    알림 GlideRecord 대상에 대한 사용자 기본 설정을 재정의하는지 확인하는 알림을 지정합니다 . 알림은 알림 [sys_notification] 테이블의 GlideRecord여야 합니다.
    표 10. 반환
    유형 설명
    부울

    알림이 대상에 대한 사용자 기본 설정을 재정의하는지 여부를 나타내는 플래그입니다.

    유효한 값은 다음과 같습니다.
    • true: 대상에 대한 사용자 기본 설정이 이 알림에 대해 무시됩니다.
    • false: 대상이 사용자 기본 설정에 따라 알림을 받거나 받지 않습니다.

    이 예에서는 승인 요청 알림이 Abel Tuter의 대상 중 하나에 대한 사용자 기본 설정을 재정의하는지 확인합니다. 알림이 사용자 기본 설정을 재정의하지 않으면 대상에 알림을 받을 수 있는 권한이 부여됩니다. 그렇지 않으면 알림이 기본 설정을 재정의하므로 기본 설정이 설정되지 않습니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    var notif = new GlideRecord('sys_notification'); 
    notif.get('name', 'Approval Request'); 
    var firstDest = dests[0]; 
    if (!firstDest.isOverridden(notif)) { 
         dests[0].setActive(notif, true); 
    } else { 
         gs.print('This notification overrides user preference, so don't bother to set a preference.'); 
    } 

    PreferenceDestination - setActive(GlideRecord 알림, 부울 활성)

    알림을 받거나 받지 않을 대상에 대한 사용자 기본 설정을 지정합니다.

    isOverriden() 메서드를 먼저 호출하여 사용자 기본 설정이 무시되는지 확인할 수 있지만 필수는 아닙니다.

    표 11. 매개변수
    이름 유형 설명
    알림 GlideRecord 옵션입니다. 알림을 지정하면 대상이 해당 알림을 받거나 받지 않도록 사용자 기본 설정이 설정됩니다. 알림은 알림 [sys_notification] 테이블의 GlideRecord여야 합니다. 알림을 지정하지 않으면 대상이 모든 알림을 받거나 받지 않도록 사용자 기본 설정이 설정됩니다.
    활성 부울

    대상에 알림을 받을 수 있는 권한이 있는지 여부를 나타내는 플래그입니다.

    유효한 값은 다음과 같습니다.
    • true: 대상에 알림 수신 권한이 있습니다.
    • false: 대상에 알림을 받을 수 있는 권한이 없습니다.
    표 12. 반환
    유형 설명
    안 함

    이 예에서는 승인 요청 알림이 Abel Tuter의 대상 중 하나에 대한 사용자 기본 설정을 재정의하는지 확인합니다. 알림이 사용자 기본 설정을 재정의하지 않으면 대상에 알림을 받을 수 있는 권한이 부여됩니다. 그렇지 않으면 알림이 기본 설정을 재정의하므로 기본 설정이 설정되지 않습니다.

    var recipient = new GlideRecord('sys_user');
    recipient.get('last_name', 'Tuter');
    var prefs = new sn_notification.Preferences(recipient);
    var dests = prefs.getDestinations();
    var notif = new GlideRecord('sys_notification'); 
    notif.get('name', 'Approval Request'); 
    var firstDest = dests[0]; 
    if (!firstDest.isOverridden(notif)) { 
         dests[0].setActive(notif, true); 
    } else { 
         gs.print('This notification overrides user preference, so don't bother to set a preference.'); 
    }