web
You’re offline. This is a read only version of the page.
close
Skip to main content
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,883
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;
 
    }

    }
 
I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,974 Most Valuable Professional on at
    Issue with list class in Custom Service of Dynamics 365 FO
    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,060 Super User 2025 Season 2 on at
    Issue with list class in Custom Service
    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,883 on at
    Issue with list class in Custom Service
    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
    236,974 Most Valuable Professional on at
    Issue with list class in Custom Service
    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

Responsible AI policies

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

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade 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... 701 Super User 2025 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 588 Most Valuable Professional

#3
Sumit Singh Profile Picture

Sumit Singh 544

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans