Friday, 29 November 2013

workflow approval validation:

u have to write this code in validate method of approval class(outcomes-approve(menuitem class))

this code is for when u submitted the workflow when approveing its check the rfq is created or not
if its created workflow approved other wise it gives error message as please create rfq for this order

public static boolean validate(Common _common, Args _args)
{
    PurchReqLine                purchReqLine,PurchReqLineloc;
    PurchReqTable               purchReqTable,purchReqTableLoc;
    Workflowtrackingstatustable workflowtrackingstatustable;
    Workflowtrackingtable       workflowtrackingtable;
    PurchRFQParameters             PurchParameters;
    HcmEmployment               hcmEmployment;
    purchRFQCaseTable           PurchRFQCaseTable;
    HcmWorker                   hcmWorker;
    DirPersonUser               dirPersonUser;

    str                         a,b,approvername;
    int                         emergencyAmount,totAmount;
    boolean c=true;
    boolean                     ret = true;

    boolean checkIfLinesFullyDistributed()
    {
        switch (_args.menuItemName())
        {
            case webActionItemStr (EPPurchReqApprovalApprove) :
            case menuitemActionStr(PurchReqApprovalApprove)   :
            case webActionItemStr (EPPurchReqTaskComplete)    :
            case menuitemActionStr(PurchReqTaskComplete)      :
                return true;
            default :
                return false;
        }
    }



select PurchParameters;
    {
if(PurchParameters.RestrictRFQ == NoYes::No)
{

   if (_common.TableId == tableNum(PurchReqTable))
    {
        purchReqTable = PurchReqTable::find(_common.RecId);
        //Call checkBudget to show any budget errors
           purchReqTable.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
            ret = ret && purchReqTable.isLinesFullyDistributed();
        }
        else
        {
            PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
        }


    }
    else
    {
        purchReqLine  = PurchReqLine::find(_common.RecId);
        purchReqTable = PurchReqTable::find(purchReqLine.PurchReqTable);
        SourceDocumentLineProcessor::submitSourceDocumentLineImplementation(purchReqLine, false, SourceDocumentLineAccountingStatus::FullyDistributed);

        //Call checkBudget to show any budget errors
        purchReqLine.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && purchReqLine.isFullyDistributed();
        }
    }

    if (ret  )
    {
       PurchReqTable::throwIfRFQPending(_common.TableId == tableNum(PurchReqTable), _common.RecId);
    }

}



if(PurchParameters.RestrictRFQ == NoYes::Yes)//select PurchParameters where PurchParameters.RestrictRFQ == 1;
{

    if (_common.TableId == tableNum(PurchReqTable))
    {
        purchReqTable = PurchReqTable::find(_common.RecId);
        while select count(RecId) from PurchReqLineloc where PurchReqLineloc.PurchReqTable == purchReqTable.RecId
                                        //&& PurchReqLineloc.SCO_RFQCaseId !=""
        {
            //a = PurchReqLineloc.RecId;
            //info(strfmt("a = %1",a));

        }
        while select PurchReqLineloc where PurchReqLineloc.PurchReqTable == purchReqTable.RecId
                                        && PurchReqLineloc.SCO_RFQCaseId !=""
        {
            //b = b+1;

        }
        //info(strfmt("b = %1",b));

        if(a == b)
        {
            //info(strfmt("a =%1 b=%2 ",a,b));

            //Call checkBudget to show any budget errors
           purchReqTable.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
            ret = ret && purchReqTable.isLinesFullyDistributed();
        }
        else
        {
            PurchReqWorkflow::validateAccountingDistributions(purchReqTable.RecId);
        }


        }
        else
        {
            c= false;
            Box::stop(" RFQ have not  created for the line items ");
            return false;
        }
       // select PurchParameters where PurchParameters.RestrictRFQ == NoYes::No;
       // {


       // }



    }
    else
    {
        purchReqLine  = PurchReqLine::find(_common.RecId);
        purchReqTable = PurchReqTable::find(purchReqLine.PurchReqTable);
        SourceDocumentLineProcessor::submitSourceDocumentLineImplementation(purchReqLine, false, SourceDocumentLineAccountingStatus::FullyDistributed);

        //Call checkBudget to show any budget errors
        purchReqLine.performBudgetCheck();
        if (checkIfLinesFullyDistributed())
        {
            ret = ret && purchReqLine.isFullyDistributed();
        }
    }


    if (ret  )
    {
       PurchReqTable::throwIfRFQPending(_common.TableId == tableNum(PurchReqTable), _common.RecId);
    }

}


    }
    return ret;
}

1 comment: