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

How to iterate data contract class in D365fo

(0) ShareShare
ReportReport
Posted on by 28

Hi All,

How could i iterate the data contract class ?

MyDataContractClass myDataContractClass = FormJsonSerializer::deserializeObject(classNum(MyDataContractClass),responseJson);

[DataContractAttribute]
class MyDataContractClass
{
    String50        invoiceId, profBillId, status, message;

    [DataMemberAttribute('proformaId')]
    public String50 parmProfBillId(String50 _profBillId = profBillId)
    {
        profBillId = _profBillId;
        return profBillId;
    }

    [DataMemberAttribute('invoiceId')]
    public String50 parmInvoiceId(String50 _invoiceId = invoiceId)
    {
        invoiceId = _invoiceId;
        return invoiceId;
    }

    [DataMemberAttribute('status')]
    public String50 parmStatus(String50 _status = status)
    {
        status = _status;
        return status;
    }

    [DataMemberAttribute('error')]
    public String50 parmMessage(String50 _message = message)
    {
        message = _message;
        return message;
    }

}
 

Thanks,

Masha

I have the same question (0)
  • Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Masha,

    Do you want to iterate over parm methods from contract class?

  • it.dev Profile Picture
    28 on at

    Hi Sergei,

    yeah , i tried to deserialized the response json i get to data contract class and then want to iterate that.

    Thanks,

    Masha

  • Suggested answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Masha,

    You can use Dict* classes to iterate over members of the contract class. But what is the purpose of that iteration? You have only 4 members in your class.

    SysDictClass contractDictClass = new SysDictClass(your contract class id);
    
    Set methods = contractDictClass.methods(true, false, true);
    
    SetEnumerator methodsEnumerator = methods.getEnumerator();
    
    while(methodsEnumerator.moveNext())
    {
        DictMethod dictMethod = methodsEnumerator.current();
    
        DataMemberAttribute dataMember = dictMethod.getAttribute(classStr(DataMemberAttribute));
    
        if (dataMember)
        {
            // Do something
        }
    }

  • it.dev Profile Picture
    28 on at

    Hi sergei,

    for the example, i get this json response

    [
        {
            "proformaId": "XXX",
            "invoiceId": "YYY",
            "error": "Unit not exists",
            "status": "failed"
        },
        {
            "proformaId": "ZZZ",
            "invoiceId": "AAA",
            "status": "success"
        }
    ]

    and want to iterate that into my data contract class attribute

    Thanks,

    Masha

  • Verified answer
    Sergei Minozhenko Profile Picture
    23,093 on at

    Hi Masha,

    So you have several entries in JSON and want them all to be converted to contract. In this case, you need to use deserializeCollection method

    List collection = FormJsonSerializer::deserializeCollection(classNum(List), json_string, types::Class, classStr(MyContract));

  • it.dev Profile Picture
    28 on at

    Hi Sergei,

    Thanks a lot, really appreciate for your help

    Masha

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
Martin Dráb Profile Picture

Martin Dráb 646 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 285 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans