2017-01-23 141 views
0

我需要第二雙眼睛來幫助我編寫此代碼。具體而言,存在導致工作流程無法啓動的情況。Servicenow審批工作流程代碼

  1. 「部門」是不確定每當請求的部門是空
  2. 有些時候跳過批准true和false(我不知道怎麼寫這部分)
  3. 這個審批工作流代碼的情況下是幫助通過的ServiceNow(不通過服務目錄)的後端創建門票

if (gs.nil(current.assignment_group)) { 
    if (!gs.nil(current.variable_pool.requested_for_department)) { 
     department = current.variable_pool.requested_for_department; 

     gs.log('0 ' + current.variable_pool.requested_for_department); 
    } 
    else if (!gs.nil(current.u_requested_for.department)) { 
     department = current.u_requested_for.department; 

     gs.log('1 ' + current.u_requested_for.department); 
    } 

    //If request was not created by e-mail. 
    if (current.u_email_creation != 2 && gs.nil(current.assignment_group)) { 

     //Finds value in Catalog Appr Fulfill Group table where Requestor Department IS NOT empty. 
     var vardept = new GlideRecord('u_catalog_appr_fulfill_group'); 
     vardept.addQuery('u_catalog_item', current.cat_item); 
     vardept.addQuery('u_requestor_department', department); 
     vardept.query(); 

     gs.log('2 approver ' + department); 

     //If record exists and the approval group for that item is not empty and approvals are not skipped... 
     if (vardept.next()){ 

      if (!gs.nil(vardept.u_catalog_item_approval_group) && vardept.u_skip_approval == false) { 
       //If record exists and the approval group for that item is not empty and approvals are not skipped... 

       //Current assignment group sets to the approval group from Catalog Appr Fulfill Group table. 
       current.assignment_group = vardept.u_catalog_item_approval_group; 

       gs.log('3 approver '); 
      } 
     } 

     else { 

      gs.log('4 approver '); 
      //Finds value in Catalog Appr Fulfill Group table where Requestor Department IS empty. 
      var vardept2 = new GlideRecord('u_catalog_appr_fulfill_group'); 
      vardept2.addQuery('u_catalog_item', current.cat_item); 
      vardept2.addNullQuery('u_requestor_department'); 
      vardept2.query(); 

      //If record exists and the Requestors department for that item is empty and approvals are skipped... 
      if (vardept2.next()) { 

       //If record exists and the Requestors department for that item is empty and approvals are NOT skipped... 
       if (!gs.nil(vardept2.u_catalog_item_approval_group) && vardept2.u_skip_approval == false) { 
        //Set assignment group to the record's approval group from Catalog Appr Fulfill Group table. 
        current.assignment_group = vardept2.u_catalog_item_approval_group; 

        gs.log('4 approver ' + vardept2.u_catalog_item_approval_group); 
       } 

      } 

      else if (gs.nil(group2.u_skip_approval) && current.assignment_group == '') { 
       gs.log('5'); 
       //If no record is found, set assignment group to Helpdesk Remote Approvers (For catalog items not in Catalog Appr Fulfill Group table). 
       current.assignment_group.setDisplayValue('Helpdesk Remote Approvers'); 
      } 
     } 
    } 
} 
+0

你應該突出你的疑問,而不是簡單地在這裏粘貼代碼..... – Rupsingh

回答

0

好奇:你在運行這個工作流代碼時面對哪個表?如果是請求表,您可以直接點到部門,因爲請求表已具有此字段/列:sc_request.requested_for.department。不知道爲什麼你創建了一個名爲requested_for_department的自定義變量?