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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Issue with list class in Custom Service

(1) ShareShare
ReportReport
Posted on by 1,909
Dears,
 
I'm trying to pull the list of customers. I use below code to get the list of customers. But the method is not returned any customer list.  
 
public class CustomerService
{
    [AifCollectionTypeAttribute('return', Types::Class, classStr(CustomerRequest))
    
    ]
       public List getCust()
    {
        // var   response   = new CustomerResponse();
        CustomerRequest _request;
        List custlist = new List(Types::Class);
        ListEnumerator CustEnumerator;
        CustTable custTable;
        while select *from custTable
        {
            _request = new CustomerRequest();
            _request.parmCustAccount(custTable.AccountNum);
            custlist.addEnd(_request);
        }
        return custlist;
 
    }

    }
 
  • Verified answer
    Martin Dráb Profile Picture
    240,807 Most Valuable Professional on at
    Maybe the method works flawlessly and the reason why it doesn't return any customers is that you're using a wrong company, where no customers exists.
     
    Note that you don't need to just observe the result and guess what's going on. You can use the debugger to see what exactly happens in your code.
  • Verified answer
    Layan Jwei Profile Picture
    8,301 Super User 2026 Season 2 on at
    Hi Faqruddin,
     
    When you debug, does it enter the while loop? Or does it skip it? If it skips it, as Martin said, check CustTable.DataAreaId when debugging, it might be DAT company
     
    Thanks,
    Layan Jweihan
     
  • Verified answer
    Faqruddin Profile Picture
    1,909 on at
    Thank you for your valuable advices. I change my code as follows as per your advice. Its little bit tricky part while using List class. inside the get() method to return as collection data. It works as follows.
     
    //[DataContractAttribute]
    [DataContract]
    public class AXCustomerContract
    {
        DataAreaId dataAreaId;
        [DataMemberAttribute("dataAreaId")]
        public DataAreaId parmDataAreaID(DataAreaId _areaId = dataAreaId)
        {
            dataAreaId = _areaId;
            return dataAreaId;
        }
        //[DataMemberAttribute("CustomerAccount")]
        //public CustAccount paramCustomerAccount(CustAccount _custAccount = custAccount)
        //{
        //    custAccount = _custAccount;
        //    return custAccount;
        //}
    }
     
     
     class AXCustomerGeterSetter
    {
        CustAccount     custAccount;
        DataAreaId dataAreaId;
        [DataMemberAttribute("dataAreaId")]
        public DataAreaId parmDataAreaID(DataAreaId _areaId = dataAreaId)
        {
            dataAreaId = _areaId;
            return dataAreaId;
        }
        [DataMemberAttribute("custAccount")]
        public custAccount parmCustAccount(custAccount _custAccount = custAccount)
        {
            custAccount = _custAccount;
            return custAccount;
        }
    }
     
     
    public class AXCustomerService
    {
        [AifCollectionType('return', Types::Class, classStr(AXCustomerGeterSetter))]
        public List getCust(AXCustomerContract _req)
        {
            // var   response   = new CustomerResponse()
            CustTable custTable;
            DataAreaId dataAreaId;
            List custlist = new List(Types::Class);
          
            ;
            dataAreaId = _req.parmDataAreaID();
            while select *from custTable where custTable.DataAreaId == dataAreaId
            {
                AXCustomerGeterSetter response = new AXCustomerGeterSetter();
                
                response.parmDataAreaID(custTable.DataAreaId);
                response.parmCustAccount(custTable.AccountNum);
                custlist.addEnd(response);
            }
            return custlist;
     
        }
    }
     
  • Martin Dráb Profile Picture
    240,807 Most Valuable Professional on at
    It's strange you're happy with it, because you have a serious bug there. You filter CustTable by DataAreaId, but you forgot to make the query cross-company, therefore it'll work correctly only if you're currently logged to the same company as in dataAreaId variable. You should add crossCompany keyword to the select statement. An alternative approach is using a changeCompany block.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

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

#1
Martin Dráb Profile Picture

Martin Dráb 475 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 399 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 374

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans