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 :
Microsoft Dynamics AX (Archived)

AX RTW Custom services Filter option?

(0) ShareShare
ReportReport
Posted on by 656

Hi All,

I have created one custom service to fetch customer details(selected fields: AccountNum, FirstName, LastName) of all customers for testing purpose to implement the similar procedure for our integration projects.

Created datacontract, service class, service and then service group. And my service is working fine  and I am able to fetch data from AX using authentication token using url such as:

https://*****devaos.cloudax.dynamics.com/api/services/TestIntegrationgrp/CustCustomerServ/Getcustomers

Code that I have used:

class CustCustomerSer

{

//Fetch customer

[SysEntryPointAttribute(true),AifCollectionTypeAttribute('return', Types::Class, classStr(CustCustomerDC))]

public List GetCustomers()

{

CustCustomerDC objcontract;

CustTable objcusttable;

List custList = new List(Types::Class);

while select * from objcusttable

{

objcontract = new CustCustomerDC();

objcontract.parmcustaccount(objcusttable.AccountNum);

if(objcusttable.partyType() == dirpartytype::Person)

{

objcontract.parmcustFName(DirPersonname::find(objcusttable.party).FirstName);

objcontract.parmcustLName(DirPersonname::find(objcusttable.party).LastName);

}

else

{

objcontract.parmcustFName(dirorganizationName::find(objcusttable.party).Name);

}

custList.addEnd(objcontract);

}

return custList;

}

Then, I was trying to get the filtered records(same as we do for data entities where we can apply Odata filters). But I am unable to filter records, I tried many things such as

https://******.cloudax.dynamics.com/api/services/TestIntegrationgrp/CustCustomerServ/Getcustomers(AccountNum="004002")

I wonder if it is possible??Or I might be missing something in code.

Also, I am trying to write some method to insert the record using 3 parameters as in mentioned code but unable to do.

Thanks in Advance!

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    No, it's not possible, because it's not an OData service.

    If you have just a few such scenarios, you can add parameters to your custom service, or create several specialized service operations (e.g. GetAllCustomer, GetCustomerById and so on).

    If you want the same querying options as with OData services, use an actual OData service.

    Regarding you problem with inserts, you will have to give us more information.

  • Saddaf Khan Profile Picture
    656 on at

    Thanks for replying.

    I have created new method as getCustomerById and provided customer account as parameter.

    public List GetCustomerbyID(CustAccount _CustAccount)

       {

    ///code same as above

    }

    Now, if I am trying to use the the webapi as

    https://*****devaos.cloudax.dynamics.com/api/services/TestIntegrationgrp/CustCustomerServ/getCustomerbyID("004002")

    its throwing an error as 404 not found

    and if I am trying without parameter I am getting an error as

    {

     "Message": "An unhandled exception was caught by the X++ Custom Services controller - Parameter count mismatch..",

     "ExceptionType": "TargetParameterCountException",

     "ActivityId": "7828bbac-9259-0005-a9df-29785992d101"

    }

    I suppose I am missing a way of passing a parameter here??

    Thanks.

  • Suggested answer
    Martin Dráb Profile Picture
    237,882 Most Valuable Professional on at

    This is a RESTful custom service, expecting a JSON-serialized contract. Please look at https://github.com/Microsoft/Dynamics-AX-Integration/blob/master/ServiceSamples/ServiceTests/JsonTests.cs to see an example how to use it.
    Again - it's not an OData service, so trying to use OData syntax won't work.

    AX uses several different types of services and you have to be aware which type you're using in the moment and consume it appropriately.

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 > 🔒一 Microsoft Dynamics AX (Archived)

#1
Priya_K Profile Picture

Priya_K 4

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#3
Sukrut Parab Profile Picture

Sukrut Parab 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans