이메일 알림에 대한 스크립팅 예시

  • 릴리스 버전: Zurich
  • 업데이트 날짜 2025년 07월 31일
  • 소요 시간: 3분
  • 이메일 알림 스크립팅의 예입니다.

    이메일 알림에 대한 스크립팅 예시

    간단한 텍스트 문자열은 메일 스크립트가 작동하는 방식의 가장 기본적인 예입니다. 이 스크립트는 "인시던트 번호 - INC00001"를 출력합니다.
    template.print("Incident number - "+ current.number);
    이와 같은 고급 스크립트는 기본 시스템 이메일 템플릿을 탐색하여 찾을 수 있습니다.
    template.print("Summary of Requested items:<br />");  
    var now_GR = new GlideRecord("sc_req_item");
    now_GR.addQuery("request", current.sysapproval);
    now_GR.query();
    while(now_GR.next()) {
      template.print(now_GR.number + ":  " + now_GR.quantity + " X " + now_GR.cat_item.getDisplayValue() 
                       + " at " + now_GR.cat_item.price.getDisplayValue() + " each <br />");
    }
    이메일 내에서 필드 값을 동적으로 변경하려면 <mail_script> 구문 내에서 다음 함수를 사용합니다.
    ...
    email.setFrom(current.caller_id.email);
    email.setReplyTo("joe.employee@yourcompany.com");
    email.setSubject("This is the new subject line");
    email.setBody("This is the new body");
    ...
    instance_name 속성을 사용하면 인스턴스 간에 마이그레이션할 때 알림이 계속 작동합니다.
    dothis();
     
    function dothis(){
        var now_GR =new GlideRecord('sys_attachment');
        now_GR.addQuery('table_sys_id',current.sys_id);
        now_GR.query();while(now_GR.next()){
            template.print('Attachment: <a href="https://'+ gs.getProperty('instance_name')+'             .service-now.com/sys_attachment.do?sys_id='+ now_GR.sys_id+'">'+ now_GR.file_name+'</a>');}}
    메일 스크립트 내의 이메일 개체를 사용하여 복사 및 숨은 참조 수신자를 지정할 수 있습니다.
    //email.addAddress(type, address, displayname);
        email.addAddress("cc","john.copy@example.com","John Roberts");
        email.addAddress("bcc","john.secret@example.com","John Roberts");
    다음은 복사된 수신자로 사용자를 watch_list 추가하는 예제 스크립트입니다.
    if(!current.watch_list.nil()){
       //get watch list addresses and add to cc
       var watcherIds = current.watch_list.split(",");
     
       //get user records
       var user = new GlideRecord("sys_user");
       user.addQuery("sys_id", watcherIds);
       user.addQuery("notification",2); 
       //email
       user.addQuery("email","!=","");
       user.query();
     
       while(user.next()){
          //add to cc list    
          email.addAddress("cc", user.email, user.getDisplayValue());}}