승인 할당 스크립트

  • 릴리스 버전: Zurich
  • 업데이트 날짜 2025년 07월 31일
  • 소요 시간: 8분
  • 유용한 승인 및 할당 스크립트의 검색 가능한 버전입니다.

    경고:
    여기서 설명하는 사용자 지정은 특정 인스턴스에서 사용하도록 개발되었으며, Now Support에서 지원되지 않습니다. 이 메서드는 있는 그대로 제공되며 구현 전에 철저히 테스트되어야 합니다. 이 사용자 지정에 대한 모든 질문과 의견을 커뮤니티 포럼에 게시합니다.

    Viewing my approvals참조 .

    ESS 요청에 대한 그룹 할당
    다음 할당 규칙 스크립트는 모든 ESS 요청에 대한 그룹을 자동으로 할당합니다.
    if(current.opened_by.roles==""){
        current.assignment_group.setDisplayValue('Network');
        current.update();}
    제공 계획 작업에 따라 그룹에 카탈로그 항목 할당
    이 할당 규칙은 데스크톱 그룹에 할당된 카탈로그 작업이 있는 배달 계획을 사용하는 경우 데이터베이스 그룹에 서비스 카탈로그 항목을 할당합니다.
    //Return catalog items that have no group but do have a delivery plan assigned
    var ri =new GlideRecord("sc_cat_item");
    ri.addQuery("group","=",null);
    ri.addQuery("delivery_plan","!=",null);
    ri.query();
    while(ri.next()){
        gs.log("Found an item");
        //Return tasks that point to the same delivery plan as the above item
        var dptask =new GlideRecord("sc_cat_item_delivery_task");
        dptask.addQuery("delivery_plan","=",ri.delivery_plan);
        dptask.query();while(dptask.next()){
            gs.log("Found a task");var gp = dptask.group.getDisplayValue();
            gs.log(gp);//If the task is assigned to desktop, assign the item's group to desktop
            if(dptask.group.getDisplayValue()=="Desktop"){
                ri.group.setDisplayValue("Desktop");
                gs.log("updating "+ ri.getDisplayValue());
                ri.update();break;}}}
    하나의 작업으로 항목 할당
    이 할당 규칙은 특정 그룹에 연결된 작업이 하나만 있는 카탈로그 항목을 자동으로 할당합니다.
    //Get the catalog item for the current requested item
    var scCatItem =new GlideRecord("sc_cat_item");
    if(scCatItem.get('sys_id', current.cat_item)){
    // If the catalog item already has an assignment group or if using workflow we don't need to make an assignment
      if(!scCatItem.delivery_plan.nil()&& scCatItem.group.nil()){
            var dpTask =new GlideRecord("sc_cat_item_delivery_task");
            dpTask.addQuery("delivery_plan","=",scCatItem.delivery_plan);
            dpTask.query();
            if(dpTask.getRowCount()==1&& dpTask.next()){
            // Check that there is only 1 record in the GlideRecord
                dpTask.group;}}}
    작업 부하를 기준으로 할당

    유형: 비즈니스 규칙

    설명: 활성 인시던트 양이 가장 적은 할당 그룹 구성원을 기준으로 할당 대상을 채웁니다.

    매개변수:
    • 순서: 담당 규칙 이후에 실행하려는 경우 >1000
    • 조건: current.assigned_to== '' && current.assignment_group != ''
    • 시기: 이전, 삽입/업데이트
    var assignTo = getLowestUser();
    gs.addInfoMessage("assigning to is "+ assignTo);
    current.assigned_to= assignTo;
     
    function getLowestUser(){
      var userList =new Array();
      var cg =new GlideRecord('sys_user_grmember');
      cg.addQuery('group', current.assignment_group);
      cg.query();
      while(cg.next()){
        var tech = cg.user.toString();
        var cnt = countTickets(tech);
        gs.addInfoMessage("Tech counts "+ cg.user.name+' '+ cnt +" "+ tech);
        userList.push({ sys_id: tech,name: cg.user.name, count: cnt });}
    
      for(var i=0; i < userList.length; i++){
        gs.addInfoMessage(userList[i].sys_id+" "+ userList[i].name+" "+ userList[i].count);}
      userList.sort(function(a, b){
        gs.addInfoMessage("Sorting: "+ a.sys_id+"("+ a.count+");
        "+ b.sys_id+"("+ b.count+")");
        return a.count- b.count;});
    
      if(userList.length<=0)return"";
      return userList[0].sys_id;}
     
    function countTickets(tech){
      var ct =new GlideRecord('incident');
      ct.addQuery('assigned_to',tech);
      ct.addQuery('active',true);
      ct.query();
      return ct.getRowCount();}
    범주 변경 시 담당 규칙 실행

    유형: 클라이언트 스크립트.

    테이블: 인시던트

    설명: 이 예는 인시던트 내의 범주 필드에 있는 onChange 클라이언트 스크립트입니다. 참고 :이 스크립트는 동기 AJAX를 사용하는 데 사용됩니다 (비동기 동작은 ajaxRequest 호출의 세 번째 매개 변수로 지정됩니다). 아래 구현에서는 비동기 AJAX를 사용합니다. 동기 버전 사용의 단점은 네트워크 응답 문제로 인해 브라우저가 중단될 수 있다는 것입니다.
    // Make an AJAX request to the server to get who this incident would be
    // assigned to given the current values in the record. This runs the assignment 
    // rules thathave been defined in System Policy and returns the assigned_to and 
    // the assignment_group
     
    function onChange(control, oldValue, newValue, isLoading){
      if(isLoading){return;
      // No change, do not do anything
      }
    
       // Construct the URL to ask the server for the assignment
      var url ="xmlhttp.do?sysparm_processor=AJAXAssignment&sys_target=incident";
      var uv = gel('sys_uniqueValue');
      if(uv){
            url +="&sys_uniqueValue="+ uv.value;}
      // Make the AJAX request to the server and get the response
      var serial = g_form.serialize();
      // get all values currently assigned to the incident
      var response = ajaxRequest(url, serial,true, responseFunc);}
     
    // This callback function handles the AJAX response.
    function responseFunc(response){
      varitem= response.responseXML.getElementsByTagName("item")[0];
      // Process the item returned by the server
      if(item){
      // Get the assigned_to ID and its display value and put them on the form
        varname=item.getAttribute("name");
        var name_label =item.getAttribute("name_label");
        if(name_label &&name){
          g_form.setValue('assigned_to',name, name_label);}
        else{
          g_form.setValue('assigned_to','','');}
        // Get the assignment_group ID and its display value and put then on the form
        var group =item.getAttribute("group");
        var group_label =item.getAttribute("group_label");
        if(group_label && group){
          g_form.setValue('assignment_group', group, group_label);}
        else{
          g_form.setValue('assignment_group','','');}}}
    사용자 지정 승인 UI 매크로
    사용자 지정 승인 UI 매크로 생성에 대한 자세한 내용은 다음 문서를 참조하십시오 UI 매크로.