Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX (Archived)

AIF: get a method return value from a contract class

Posted on by 1,169

Hi,

I am creating a custom service which returns multiple records of the CustTable table. But, how to add some of the methods present on the table?

eg. the parm method will accept AccountNum and return customer address (CustTable.address()).

Regards,

Abhinay

*This post is locked for comments

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    [quote user="Martin Dráb"]What problem do you have with it? How else would you like to solve it? The number of objects comes from your own requirements and your choice to use a custom service.[/quote]

    The first and foremost, it will be an instance of the contract and not a table that would be returned.

    That means additional code writing at the web service consumption level for iterating through the values.

    [quote user="Martin Dráb"]And no, creating these objects won't have any measurable impact on performance, especially if we compare it with time necessary for DB queries and data transfer via network.[/quote]

    That answers my question, thanks.

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: AIF: get a method return value from a contract class

    What problem do you have with it? How else would you like to solve it? The number of objects comes from your own requirements and your choice to use a custom service.

    If you want to represent 100 entities, you'll create 100 objects; that's how object-oriented programming usually works. And no, creating these objects won't have any measurable impact on performance, especially if we compare it with time necessary for DB queries and data transfer via network.

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    Thank you Martin.

    This is not one of the most elegant solutions AX has to offer, but would work in my case.

    I am not sure if it would be efficient performance wise with large number of records.

    I am adding as many instances of the contract class to a list as the number of records selected from the tables.

    Regards,

    Abhinay Tharwal

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: AIF: get a method return value from a contract class

    I mentioned three customers only because I continued your own example. The list can contain any number of items, of course.

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    [quote user="Martin Dráb"]For instance, I have no idea what you mean by the selected record.[/quote]

    When the web-service is consumed and CustTable records are fetched, which record is, at that moment, being processed.

    So, maybe out of Cust001, Cust002, Cust003, ...... Cust00n records, customer Cust009's address needs to be fetched.

    [quote user="Martin Dráb"]If your goal is to return three customers with addresses, I would expect your service returning a list with three objects.[/quote]

    No, the number of records returned would vary and depend on the filters (e.g. modified date range)

    [quote user="Martin Dráb"]Also note that you may be able to use the query service instead of building a custom service.[/quote]

    This will potentially risk exposing the data to unintentional users, and more proactive measures need to be taken to prohibit that from happening. I want to limit the scope of the service, at minimum number of steps, but that should not the part of discussion of this thread.

    Regards,

    Abhinay

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: AIF: get a method return value from a contract class

    I think you're too deep in little implementation details when we should be talking about what data you want to get. Don't forget that we know nothing about your requirements except of what you told us, which isn't much. For instance, I have no idea what you mean by the selected record.

    If your goal is to return three customers with addresses, I would expect your service returning a list with three objects. Each of them would be a data contract class containing all necessary information, including address.

    Also note that you may be able to use the query service instead of building a custom service.

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    Hi Martin,

    I have to return CustTable records. The parm method can hold only one value in the address variable. I cannot use List collection class as I would not be able to map which address is linked to which customer. I can concatenate the customer account-num and the address in the list, separated by a delimiter (say pipe), but I was wondering if there is a built-in way of achieving this.

    So, if you consider my example from the earlier post, if there are say three rows from the CustTable, viz. Cus001, Cus002, Cus003 and depending on the record selected I have to return the address.

    It would be easier if I could return a Map collection class. If it works for CustTable, I would use the same technique on the other tables I have to return.

    This is pretty much it.

    Please let me know, should you need more details.

    Regards,

    Abhinay

  • Martin Dráb Profile Picture
    Martin Dráb 230,214 Most Valuable Professional on at
    RE: AIF: get a method return value from a contract class

    Sorry, I can't help you with your problem with data selection unless you don't provide more details.

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    [quote user="Martin Dráb"]You can populate a data contract class by any code (e.g. by CustTable.address()) and return this class from your custom service.[/quote]

    Hi Martin,

    Well, the problem is that, I am returning multiple rows, and the code does not allow me to add any select statement/ method (the service group deployment fails if I do). So, if there are say three rows from the CustTable, viz. Cus001, Cus002, Cus003 and depending on the record selected I have to return the address.

    Regards,

    Abhinay

  • Abhinay Tharwal Profile Picture
    Abhinay Tharwal 1,169 on at
    RE: AIF: get a method return value from a contract class

    [quote user="Martin Dráb"]You can populate a data contract class by any code (e.g. by CustTable.address()) and return this class from your custom service.

    By the way, if you need all details of a customer, wouldn't CustCustomerService document service be a better choice?

    [/quote]

    Thank you Martin, I will try that.

    I have simplified my question. Actually the service returns records from multiple tables and only one web service is to be created.

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans