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

Custom JSON service with Array as input parameter - D365 F&O

(0) ShareShare
ReportReport
Posted on by 110

Hi All,

I have requirement where I need to create custom JSON service which accepts array of Sales order numbers, hold codes as input. I am able to create custom JSON service by passing single values for SalesID and hold code. I am not able to figure out how to pass array of values for the same.

Do we need to create Contract and controller  classes to handle this?

Also would like to get an opinion on using JSON custom service VS OData entity? Which one would be better with respect to performance. I have to process big chunk of sales orders into "On hold" using this interface.

Thank you ! 

I have the same question (0)
  • Verified answer
    nmaenpaa Profile Picture
    101,166 Moderator on at

    Typically OData is slow, and you will get better performance with custom services.

    For receiving multiple order numbers in single field, just create a string field in your service, and let the caller pass comma separated values in it. So the input could be "123, 585, 959". Then in x++ you can parse it and get three sales order numbers from it.

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    The service method can accept a list of strings. Like this:

    [AifCollectionType('_salesOrderIds', Types::String)]
    public void doStuff(List _salesOrderIds)
    {
    }

    Or it can accept a data contract class that has a list as one of its properties.

  • d365Dev Profile Picture
    110 on at

    Thanks Martin for quick reply. I want to know whether is it possible to pass 2 fields as list of strings , for example

    [AifCollectionType('_salesOrderIds', Types::String, '_holdcodes',Types::String)]

    public void onhold(List _salesOrderIds,List _holdcodes)

    {

    }

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    No, your code is not correct. The first parameter of the attribute identifies the method parameter name, the second identifies the type. The the third parameter is used to for the type name, e.g. if the type is Class, it says which class. It's not useful for strings. You're trying to use it for something else and it simply can't work.

    If you want to do this thing for two method parameters, you need two collection type attributes, one for each parameter:

    [
        AifCollectionType('_salesOrderIds', Types::String),
    	AifCollectionType('_holdcodes', Types::String)
    ]
    public void onHold(List _salesOrderIds, List _holdcodes)
    {
    }

  • d365Dev Profile Picture
    110 on at

    Hi Martin,

    I could able to create a JSON having parameter as Array lists. I did test using POSTMAN and it worked fine too.

    code snippet:

    [

       AifCollectionType('_salesOrderIds', Types::String),

    AifCollectionType('_holdcodes', Types::String)

    ]

    public void onHold(List _salesOrderIds, List _holdcodes)

    {

    //Code to put on hold

    }

    POSTMAN input Body:

    {

    "_salesOrderIds": ["SO1","SO2"],

    "_holdcodes": ["weather","credit"]

    }

    If my service needs to accept below JSON format as input, should I need to manage by writing data contract class or is there any other way we can achieve ?

    [

    {

    "_SalesOrderIds: "SO1",

    "_holdcodes":"Weather"

    }

    {

    "_SalesOrderIds: "SO1",

    "_holdcodes":"Credit"

    }

    ]

    Thank you !!

  • Verified answer
    Martin Dráb Profile Picture
    237,990 Most Valuable Professional on at

    Yes, you need a data contract class for the JSON object.

    By the way, please always use Insert > Insert code (in the rich formatting view) to paste source code. It'll make it easier to read and work with.

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
Abhilash Warrier Profile Picture

Abhilash Warrier 669 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 423 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans