Sunday, October 26, 2014

Hirerachy position and QueryToRDP Report Example


// based on the Hirerachy position value ill display
static void hirerachypositionandReportQuerytoRdp(Args _args)
{
     str UserId;

    // Hierarchy position test class
    // HierarchyPosition Table
    /*class RecursionPosition
    {
        str UserId;
    }
    void recursiveCallProj(HcmPositionRecid    _position = 0)
    {
    HcmPositionHierarchy HcmPositionHierarchy;
    HierarchyPosition   hierarchyPosition;
    HcmPosition         posi;
    HcmWorker           work;
    int64               recid;
    ;
    while select HcmPositionHierarchy
    where HcmPositionHierarchy.ParentPosition == _position
    {
        // setprefix("1");
        //info(strFmt("%1",HcmPositionHierarchy.Position));
        select Posi where posi.RecId == HcmPositionHierarchy.Position;
        recid = hcmposition::getWorker(posi.RecId);
        select work where work.RecId == recid;
        hierarchyPosition.Position = work.RecId;
        hierarchyPosition.userid = curuserid();
        hierarchyPosition.insert();

        this.recursiveCallProj(HcmPositionHierarchy.Position);

        }
        }
    public static void postion(str userid = curUserId())
    {
    HcmPositionRecid        _position; //= 5637144597;
    HcmPositionHierarchy    HcmPositionHierarchy;
    RecursionPosition       RecursionPosition;
    HcmPosition             posi;
    int64                   recid;
    HcmWorker               work;
    HierarchyPosition   hierarchyPosition;
    //str UserId;

    ;
    //UserId = user;
    _position = HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::find(HcmWorker::userId2Worker(userid)).RecId).Position;
    //_position = HcmPositionWorkerAssignment::getActivePositionWorkerAssignment(HcmWorker::findByPersonnelNumber(personnelno).RecId).Position;
    RecursionPosition = new RecursionPosition();


    while select HcmPositionHierarchy
    where HcmPositionHierarchy.Position == _position
    {
        info(strFmt("%1",HcmPositionHierarchy.Position));
        select Posi where posi.RecId == HcmPositionHierarchy.Position;
        recid = hcmposition::getWorker(posi.RecId);
        select work where work.RecId == recid;
        hierarchyPosition.Position = work.RecId;
        hierarchyPosition.userid = curUserId();
        hierarchyPosition.insert();


        RecursionPosition.recursiveCallProj(HcmPositionHierarchy.Position);

    }


    }
    // Example QUery report to RDP Report class Example
    [
    SRSReportQueryAttribute(queryStr(UBMSalesEnquiryTable))
    ]





// Query TO rdp

    class UBMSalesEnquiryRegisterDP extends SRSReportDataProviderBase
    {

        UBMSalesEnquiryRegisterTmp     SalesEnquiryRegisterTmp;

    }
    private Query buildQuery(
    Query           _query,
    str             _worker)
    {

        // Add the date range on all three data sources to allow SQL to restrict the records as much as possible prior to processing
        _query.dataSourceTable(tableNum(SalesQuotationTable), 1).addRange(fieldNum(SalesQuotationTable, WorkerSalesResponsible)).value(_worker);

        return _query;
    }
    [SRSReportDataSetAttribute("UBMSalesEnquiryRegisterTmp")]
    public UBMSalesEnquiryRegisterTmp getUBMSalesEnquiryRegisterTmp()
    {
        select * from SalesEnquiryRegisterTmp;
        return  SalesEnquiryRegisterTmp;
    }
    [SysEntryPointAttribute(false)]
    public void processReport()
    {
    QueryRun                queryRun;
    SalesQuotationTable     salesQuotationTable;
    HcmWorker               hcmWorker;
    str                     workerHirerchy;
    //helper.amountRemainSalesPhysical(this.SalesTableRecId);

    HierarchyPosition    hierarchyPosition;
    boolean     first = true;


    delete_from hierarchyPosition;

    RecursionPosition::postion();


    while select hierarchyPosition //where currency.CurrencyCode like "E*"
    {
        if(first)
        {
            workerHirerchy = strFmt("%1,",hierarchyPosition.Position);
            first = false;
        }
        else
        {

            workerHirerchy += strFmt("%1,",hierarchyPosition.Position);
        }

    }

    queryRun = new QueryRun(this.buildQuery(this.parmQuery(),workerHirerchy));

    //queryRun = new QueryRun(this.parmQuery());

    while (queryRun.next())
    {
        salesQuotationTable                                 = queryRun.get(tableNum(SalesQuotationTable));

        SalesEnquiryRegisterTmp.QuotationId                        = salesQuotationTable.QuotationId;
        SalesEnquiryRegisterTmp.QuotationName                      = salesQuotationTable.QuotationName;
        SalesEnquiryRegisterTmp.CreateDate                         = salesQuotationTable.createDate();
        SalesEnquiryRegisterTmp.CustomerRef                        = salesQuotationTable.CustomerRef;
        SalesEnquiryRegisterTmp.CustName                           = salesQuotationTable.customerName();
        SalesEnquiryRegisterTmp.LineAmount                         = salesQuotationTable.lineAmount();
        SalesEnquiryRegisterTmp.UBMrefenquiryno                    = salesQuotationTable.UBMrefenquiryno;
        SalesEnquiryRegisterTmp.VendName                           = salesQuotationTable.VendName();
        SalesEnquiryRegisterTmp.MOE                                = salesQuotationTable.SalesOriginId;
        SalesEnquiryRegisterTmp.QuotationStatus                    = salesQuotationTable.QuotationStatus;
        SalesEnquiryRegisterTmp.ReasonId                           = salesQuotationTable.ReasonId;
        SalesEnquiryRegisterTmp.UBMEnquiryDate                     = salesQuotationTable.UBMEnquiryDate;
        SalesEnquiryRegisterTmp.WorkerSalesResponsible             = HcmWorker::find(salesQuotationTable.WorkerSalesResponsible).name();
        SalesEnquiryRegisterTmp.QuotationCategory                  = salesQuotationTable.QuotationCategory;
        SalesEnquiryRegisterTmp.Competitor                         = " ";
        SalesEnquiryRegisterTmp.insert();


    }


}*/
}

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...