jhowe
jhowe

Reputation: 10828

x++ get resourcename from recid

I've heavily customised the Project Transaction Report (projlisttransproj, and I'm displaying Resource ID. I would like to display the name of this resource instead (see insert method). I'm fairly new to x++ development so step by step would be greatly appreciated. I have had a look in projtrans class and found below, but found nothing referring to name... thanks!

/// <summary>
    /// Retrieves the ID of the employee that is associated with this transaction depending on the
    /// transaction type that is returned by the <c>ProjTrans.transType</c> method.
    /// </summary>
    /// <returns>
    /// The <c>RecID</c> value of the employee that is associated with this transaction.
    /// </returns>
    /// <remarks>
    /// For hour, cost, and revenue transactions, the employee ID will be returned. For all other
    /// transactions, 0 will be returned.
    /// </remarks>
    public ResourceRecId projIdentResource()
    {
        ResourceRecId     resourceRecId;

        switch(this.transType())
        {
            case ProjTransType::Hour:
            case ProjTransType::Cost:
            case ProjTransType::Revenue:
                resourceRecId   = this.resource();
                break;
            default:
                resourceRecId   = 0;
        }

        return resourceRecId;
    }

enter image description here

public void insertProjTransList()
    {
        tmpProjTransListExtension.clear();
        tmpProjTransListExtension.VoucherInvoice    = projTrans.voucherInvoice();
        tmpProjTransListExtension.VoucherJournal    = projTrans.voucherOriginal();
        tmpProjTransListExtension.LinePropertyId    = projTrans.linePropertyId();
        tmpProjTransListExtension.ActivityNumber    = projTrans.activityNumber();
        tmpProjTransListExtension.CategoryId        = projTrans.categoryId();
        tmpProjTransListExtension.CostPrice         = projTrans.costPrice();
        tmpProjTransListExtension.CurrencyId        = projTrans.currencyIdSales();
        tmpProjTransListExtension.DefaultDimension  = projTrans.defaultDimension();
        tmpProjTransListExtension.SalesAmount       = projTrans.transTurnoverMST();
        tmpProjTransListExtension.CostAmount        = projTrans.transCostMST();
        tmpProjTransListExtension.ProjIdOrig        = projTrans.projId();
        tmpProjTransListExtension.ProjId            = firstProjId;
        tmpProjTransListExtension.Qty               = projTrans.qty();
        tmpProjTransListExtension.SalesPrice        = projTrans.salesPrice();
        tmpProjTransListExtension.TransDate         = projTrans.transDate();
        tmpProjTransListExtension.Txt               = projTrans.txt();
        tmpProjTransListExtension.TransType         = projTrans.transType();
        tmpProjTransListExtension.ProjId            = firstProjId;
        TmpProjTransListExtension.ProjName          = firstProjName;
        tmpProjTransListExtension.Type              = ProjCategory::find(projTrans.categoryId()).CategoryType;
        TmpProjTransListExtension.Resource          = ProjTrans.resource(); //Want Name of resource not ID
        tmpProjTransListExtension.insert();
    }

Upvotes: 3

Views: 853

Answers (1)

Matej
Matej

Reputation: 7627

You can get worker's name with HcmWorker::find(ProjTrans.resource()).name().

Upvotes: 1

Related Questions