web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

Group by not getting desired result

(0) ShareShare
ReportReport
Posted on by 1,836
i was trying to get the worker name from the query but getting all the data blank in debugger , i tried to test the query in sql but i need to do group by all fields can please any on know how can i get the worker email and name from the code my code is below .
 
I have the same question (0)
  • Dineshkarlekar Profile Picture
    1,836 on at
    here is my code 
    public void processoperation()
        {
            CustTable        custTable;
            CustTrans        custTrans;
            HcmWorker        hcmWorker;
            Email            email;
            Name             name;
            DTFinancialDimensionView    financialDim;
          
    
            while select * from custTable
                join custTrans 
                       where custTable.AccountNum == custTrans.AccountNum
                         && custTrans.Closed == dateNull()
                join financialDim group by financialDim.Worker
                       where financialDim.RecordId == custTrans.DefaultDimension
            {
                select * from hcmWorker 
                       where hcmWorker.PersonnelNumber == financialDim.Worker;
    
                email = HcmWorker.email();
                name  = HcmWorker.name();
            }
    }
     
  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at
    What did you find when you debugged your code? You know how to use the debugger, don't you?
     
    I assume that no hcmWorker was found, right? That explains why both email and name are empty, right?
     
    You next step in debugging it looking at the value you're (unsuccessfully) using to find a worker, i.e. the value in financialDim.Worker. It's either empty or it returns something that it's a valid personnel number.
     
    With this information, look for the bug in your view (DTFinancialDimensionView).
     
     
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi ,martin
     
    i have made changes to my code, i am getting all the worker but can i get name and mail id from hcm worker or i need to use user info to get name and mail id , below is my code 
    public void processoperation()
        {
            CustTable        custTable;
            CustTrans        custTrans;
            HcmWorker        hcmWorker;
            Email            email;
            Name             name;
            DTFinancialDimensionView    financialDim;
          
    
            while select  custTable
                join custTrans 
                       where custTable.AccountNum == custTrans.AccountNum
                         && custTrans.Closed == dateNull()
                      
                join Worker from financialDim group by financialDim.Worker
                       where financialDim.RecordId == custTrans.DefaultDimension
            {
                select PersonnelNumber from hcmWorker group by hcmWorker.PersonnelNumber
                       where hcmWorker.PersonnelNumber == financialDim.Worker;
    
                email = HcmWorker.email();
                name  = HcmWorker.name();
            }
    }
     
     
     
  • Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at
    I'm sorry, but it's not clear to me what you found when you debugged your code. Please give us more information.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi martin ,
    when i debugged the code i am getting the  value of findimension.Worker and i am passing that value in hcm worker but when in debugger the email and name field are showing blank .  i am getting values in my select stratement so email and name must get populate but it is not happening when i debg not getting where i am getting wrong .
     
    select PersonnelNumber from hcmWorker group by hcmWorker.PersonnelNumber
                       where hcmWorker.PersonnelNumber == financialDim.Worker;
  • Dineshkarlekar Profile Picture
    1,836 on at
     hi martin ,
     i got the name from name =hcmworker.name();    but not getting email id , can you plz suggest how can i get email id using the name i got 
     
    thanks,
    Regards,
    Dinesh 
  • Verified answer
    Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at
    Trying random pieces of code isn't a viable approach to analyze and fix bugs. You see that you're indeed not successful, therefore you have to do something better if you want better results.
     
    Throw away your latest change, because it can make things only worse, not better. What you do it effectively removing values of all fields except of PersonnelNumber. If no worker can be found for a given personnel number, do you really believe that your code can some how changed this fact? And if a worker is found, removing field values will cause a problem instead of solving anything.
     
    You said you got a value in finDmension.Worker, but not if the value is correct. If no worker can be found, it must mean that no such a worker exists in the current company. Don't you agree?
     
    Then there are questions you need to ask by yourself:
     
    1) Does DTFinancialDimensionView.Worker returns a personnel number?
    2) If not, should it?
    3) If it should return a personnel number but it doesn't, there is a bug in the view. Then there is no point in changing your code in processOperation(), because we know the cause lies elsewhere.
    4) If it shouldn't return a personnel number, then you're using the value incorrectly. Check out what it is that Worker field actually contains.
    5) If it returns a personnel number that can be found in HcmWorker table but not by select hcmWorker where hcmWorker.PersonnelNumber == financialDim.Worker, it likely means that it's a worker from another company. What you should depends on whether DTFinancialDimensionView is expected to return for the current company only. If so, it's a bug in the view. If not, you must filter the data by the current company.
     
    By the way, you can make your debugging easier by simplifying your code and putting it to a runnable class for debugging purposes. If you wish, you can also add extra infolog message, so you don't have to check everything in debugger. For example:
    public static void main(Args _args)
    {
        CustTable                    custTable;
        CustTrans                    custTrans;
        DTFinancialDimensionView    financialDim;
    
        select firstOnly custTable
            join custTrans 
            where custTrans.AccountNum == custTable.AccountNum
               && custTrans.Closed == dateNull()
            join Worker from financialDim
                group by financialDim.Worker
                where financialDim.RecordId == custTrans.DefaultDimension;
                
        info(strFmt("PersonnelNumber: %1", financialDim.Worker);
        
        HcmWorker hcmWorker;
        
        select hcmWorker
            where hcmWorker.PersonnelNumber == financialDim.Worker;
        
        if (hcmWorker)
        {
            info(strFmt("Name: %1", hcmWorker.name());
        }
        else
        {
            info(strFmt("No worker found");
        }
    }
  • Verified answer
    Martin Dráb Profile Picture
    237,978 Most Valuable Professional on at
    If you're now getting the worked but not e-mail, it likely that the particular worker doesn't have a primary e-mail set up. Open F&O and verify contact information of the given worker.
     
    If you believe that email() should return a value, you can use the debugger to find out where your expectations aren't met.
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi martin , 
    i will do follow the steps you have mentioned below .
     
    thanks ,
    Dinesh
  • Dineshkarlekar Profile Picture
    1,836 on at
    hi 
    martin,
     you were right about passing the current company  , i am getting email id and name but how can i get it using current company i tried to pass current company but still it takes data from 'dat' can you please guide me on this 
     public static void main(Args _args)
        {
            CustTable        custTable;
            CustTrans        custTrans;
            HcmWorker        hcmWorker;
            HcmWorkerRecId   workerrecID;
            DirPersonUser    dirPersonUser;
            UserInfo         userinfo;
            Email            email;
            Name             name;
            DTFinancialDimensionView    financialDim;
            str              curCompany;
    
            curCompany = curExt();
    
            while select DataAreaId from custTable 
                join custTrans 
                       where custTable.AccountNum == custTrans.AccountNum
                         && custTrans.Closed == dateNull()
                        
                join Worker from financialDim group by financialDim.Worker
                       where financialDim.RecordId == custTrans.DefaultDimension
                         &&  custTable.DataAreaId ==  curCompany
            {
                select PersonnelNumber,person,RecId from hcmWorker group by hcmWorker.PersonnelNumber,hcmWorker.Person,hcmWorker.RecId
                       where hcmWorker.PersonnelNumber == financialDim.Worker;
    
                name  = hcmWorker.name();
                dirPersonUser.User = hcmWorker::Worker2UserID(hcmWorker.RecId);
    
                select networkAlias from userinfo 
                         join dirPersonUser  
                              where userinfo.id ==  dirPersonUser.User;
    
                email = userinfo.networkAlias;
             }
    }
     
                                                                                                 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 449 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 422 Most Valuable Professional

#3
BillurSamdancioglu Profile Picture

BillurSamdancioglu 239 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans