2017-01-23 8 views
0

Ich brauche ein zweites Paar Augen, um mir zu helfen, diesen Code zu schreiben. Insbesondere gibt es Bedingungen, die dazu führen, dass der Workflow nicht ausgelöst wird.Servicenow Genehmigung Workflow-Code

  1. ‚Abteilung‘ ist nicht definiert, wenn die für die Abteilung Gewünscht
  2. leer
  3. Es gibt Fälle, wenn Sprung Zulassungen wahr und falsch sind (ich weiß nicht, wie dieser Teil zu schreiben)
  4. Dieser Genehmigungs-Workflow Code ist zu helfen, Tickets über das Backend von ServiceNow (nicht durch den Servicekatalog)

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

Sie sollten Ihre Zweifel hervorheben, anstatt Code einfach hier einzufügen ..... – Rupsingh

Antwort

0

zu erstellen Interessant: In welcher Tabelle läuft dieser Workflow-Code? Wenn es die Anfragetabelle ist, können Sie dot direkt zur Abteilung gehen, da die Anfragetabelle bereits dieses Feld/Spalte hat: sc_request.requested_for.Department. Sie wissen nicht, warum Sie eine benutzerdefinierte Variable namens requested_for_department erstellt haben?