Thursday 12 December 2013

Skip level one approver if level two approver is time out in AWE

Skiping the level one approver we can do in two steps if Level two approver has time out and Requester is submitting the transaction for different level 2 approver.

Step1: write the below code in component Record rowinit.

Component string &TEST_Skip_Level_One;
Local string &TEST_Crrt_Approver, &TEST_AO_Approved, &TEST_SAO_Approved;


If TEST_INVOICE_HDR.TEST_CERT_STATUS = "W" Then
   &TEST_Skip_Level_One = "N";
   SQLExec("SELECT C.OPRID  FROM PS_TEST_E_INV_XREF A , PS_EOAW_STEPINST B , PS_EOAW_USERINST C WHERE A.EOAWDEFN_ID = B.EOAWDEFN_ID AND A.EOAWPRCS_ID = B.EOAWPRCS_ID AND A.EOAWTHREAD_ID = B.EOAWTHREAD_ID AND A.EOAWTHREAD_STATUS = 'P' AND A.BUSINESS_UNIT =:1 AND  A.VENDOR_SETID =:2 AND A.VENDOR_ID =:3 AND  A.INVOICE_ID =:4 AND  A.INVOICE_DT =:5 AND B.EOAWSTEP_INSTANCE = C.EOAWSTEP_INSTANCE AND C.EOAWSTEP_STATUS = 'P' ", TEST_INVOICE_HDR.BUSINESS_UNIT.Value, TEST_INVOICE_HDR.VENDOR_SETID.Value, TEST_INVOICE_HDR.VENDOR_ID.Value, TEST_INVOICE_HDR.INVOICE_ID.Value, TEST_INVOICE_HDR.INVOICE_DT.Value, &TEST_Crrt_Approver);
   If &TEST_Crrt_Approver = TEST_INVOICE_HDR.TEST_PO_OPRID Then
      SQLExec("SELECT A.TEST_AO_FLAG , A.TEST_SAO_FLAG  FROM PS_TEST_WF_INV_RECS A WHERE A.BUSINESS_UNIT =:1 AND  A.VENDOR_SETID =:2 AND A.VENDOR_ID =:3 AND  A.INVOICE_ID =:4 AND  A.INVOICE_DT =:5", TEST_INVOICE_HDR.BUSINESS_UNIT.Value, TEST_INVOICE_HDR.VENDOR_SETID.Value, TEST_INVOICE_HDR.VENDOR_ID.Value, TEST_INVOICE_HDR.INVOICE_ID.Value, TEST_INVOICE_HDR.INVOICE_DT.Value, &TEST_AO_Approved, &TEST_SAO_Approved);
      If &TEST_AO_Approved = "Y" And
            &TEST_SAO_Approved = "N" Then
         &TEST_Skip_Level_One = "Y";
      End-If;
   End-If;
End-If;

Step2: write the below code in component savepostchange( where we will trigger the approval).


import FS_COMBO_EDIT:ComboEdit;


import EOAW_CORE:*;
import EOAW_CORE:LaunchManager;
import EOAW_CORE:ApprovalManager;
import EOAW_CORE:ENGINE:*;
import EOAW_MONITOR:CLASS_DEFAULTS:*;

Declare Function createStatusMonitor PeopleCode EOAW_MON_WRK.EOAW_FC_HANDLER FieldFormula;

Local EOAW_CORE:ENGINE:AppInst &displayInst;
Local EOAW_MONITOR:CLASS_DEFAULTS:saveButtonLogicDefault &saveButton;



Component EOAW_CORE:LaunchManager &LaunchMgr;
Component EOAW_CORE:ApprovalManager &ApprovalMgr;
Component Record &HdrRecord;
Component Record &UpdRecord;
Component string &AWE_Action, &TEST_Skip_Level_One;


&HdrRecord = CreateRecord(Record.TEST_INVOICE_HDR);
GetLevel0()(1).GetRecord(Record.TEST_INVOICE_HDR).CopyFieldsTo(&HdrRecord);

&process_id = "TEST EInvoice eForm Approval";
Evaluate &AWE_Action
When "S"
   &LaunchMgr = create EOAW_CORE:LaunchManager(&process_id, &HdrRecord, %OperatorId);
   If TEST_INVOICE_HDR.TEST_CERT_STATUS = "N" Or
         TEST_INVOICE_HDR.TEST_CERT_STATUS = "D" Then
      &LaunchMgr.DoSubmit();
      &ApprovalMgr = create EOAW_CORE:ApprovalManager(&process_id, &HdrRecord, %OperatorId);
      &ApprovalMgr.AddComments(%OperatorId, &HdrRecord, TEST_INVOICE_WRK.COMMENTS);
   Else
      If TEST_INVOICE_HDR.TEST_CERT_STATUS = "W" Then
         &LaunchMgr.TerminateRunningProcess();
         
         &LaunchMgr = create EOAW_CORE:LaunchManager(&process_id, &HdrRecord, %OperatorId);
         &LaunchMgr.DoResubmit();
         
         If &TEST_Skip_Level_One = "Y" Then;
            SQLExec("SELECT A.TEST_AOUSER  FROM PS_TEST_WF_INV_RECS A WHERE A.BUSINESS_UNIT =:1 AND  A.VENDOR_SETID =:2 AND A.VENDOR_ID =:3 AND  A.INVOICE_ID =:4 AND  A.INVOICE_DT =:5", TEST_INVOICE_HDR.BUSINESS_UNIT.Value, TEST_INVOICE_HDR.VENDOR_SETID.Value, TEST_INVOICE_HDR.VENDOR_ID.Value, TEST_INVOICE_HDR.INVOICE_ID.Value, TEST_INVOICE_HDR.INVOICE_DT.Value, &TEST_AO);
            &ApprovalMgr = create EOAW_CORE:ApprovalManager(&process_id, &HdrRecord, &TEST_AO);
            &ApprovalMgr.DoApprove(&HdrRecord);
            &ApprovalMgr.AddComments(%OperatorId, &HdrRecord, TEST_INVOICE_WRK.COMMENTS);
         End-If;
      End-If;
   End-If;
   Break;
   
When "D"
   &ApprovalMgr = create EOAW_CORE:ApprovalManager(&process_id, &HdrRecord, %OperatorId);
   &ApprovalMgr.DoDeny(&HdrRecord);
   &LaunchMgr = create EOAW_CORE:LaunchManager(&process_id, &HdrRecord, %OperatorId);
   &ApprovalMgr.AddComments(%OperatorId, &HdrRecord, TEST_INVOICE_WRK.COMMENTS);
   createStatusMonitor(&ApprovalMgr.the_inst, "D", &saveButton, True);
   Break;
   
When "A"
   &ApprovalMgr = create EOAW_CORE:ApprovalManager(&process_id, &HdrRecord, %OperatorId);
   &ApprovalMgr.DoApprove(&HdrRecord);
   &LaunchMgr = create EOAW_CORE:LaunchManager(&process_id, &HdrRecord, %OperatorId);
   &ApprovalMgr.AddComments(%OperatorId, &HdrRecord, TEST_INVOICE_WRK.COMMENTS);
   createStatusMonitor(&ApprovalMgr.the_inst, "D", &saveButton, True);
   Break;
When-Other
   Break
End-Evaluate;


If &LaunchMgr.monitorEnabled Then
   createStatusMonitor(&ApprovalMgr.the_inst, "D", &saveButton, True);
End-If;


Note: Copy the code into notepad and replace "TEST"  with your client name like "AAAA"

No comments:

Post a Comment