Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Suggested answer

How to use RefRecId to get the reference value using X++.

Posted on by 171

Hi,

I am working on customization where I have to pick the data from one form to another form on some certain condition using a batch job. The problem is that I have a customized table XYOvertimeRequest in which I have a RefRecId field with the name "HCMWorker" (i.e; XYOvertimeRequest.HCMWorker) and this field is returning the name of an employee using RefGroupField. How I can use this RefRecId field to get the name of an employee in my method ProcessData() of a batch job. Here is my code,

private void ProcessData()

{

    XYOvertimeRequest           overtimeRequest;

    XYOvertimeRequestLines      overtimeRequestLines;

    ABC_BulkPayment            bulkPayment; 

   ttsBegin;

   select * from overtimeRequest

   where overtimeRequest.WorkflowState == TradeWorkflowState::Completed

   && overtimeRequest.ABC_PaymentStatus == ABC_PaymentStatus::NotPicked; 

   if(overtimeRequest.RequestID == overtimeRequestLines.RequestID)

   {

       bulkPayment.OvertimeRequestID = overtimeRequest.RequestID;

       bulkPayment.RequestDate = overtimeRequest.RequestDate;

       bulkPayment.Employee =   (overtimeRequest.HcmWorker); //Here I am finding the operand type error too, also Employee has type string.

       bulkPayment.Department = overtimeRequest.Department;

       bulkPayment.Grade = overtimeRequest.Grade;

       bulkPayment.PlanOvertimeRequestID = overtimeRequest.PlanOvertimeRequestId;

       bulkPayment.TotalHours = overtimeRequest.OTHours();

       bulkPayment.TotalAmount          = overtimeRequest.OTAmounts();

       bulkPayment.insert();

   } 

   ttsCommit; 

}

So is there is any way to get the employee name using this RefRecId, Thanks.

  • D365 FO Tech Profile Picture
    D365 FO Tech 5 on at
    RE: How to use RefRecId to get the reference value using X++.

    Thank you so much brother, Love you.

  • Blue Wang Profile Picture
    Blue Wang on at
    RE: How to use RefRecId to get the reference value using X++.

    hi bilal170795,

    Worker ID:

    HcmWorker::findByPersonnelNumber(workerID).name();

    Worker RecID :

    HcmWorker::find(workerRecid).name();

  • Suggested answer
    Sergei Minozhenko Profile Picture
    Sergei Minozhenko 23,083 on at
    RE: How to use RefRecId to get the reference value using X++.

    Hi bilal170795,

    RefRecId is a type that usually used for RecId-based relations. It means that field overtimeRequest.HcmWorker contains RecId value for record in HcmWorker table.

    To get name for worker using RecId field, you need to select record from HcmWorker (you can use find record) and use name method to get worker name

    HcmWorker::find(overtimeRequest.HcmWorker).name();

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 288,420 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,672 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans