Serialize Json with data from an dataContract class in D365FO
Views (1310)
Hi,
In this post we will see the process of serializing the data to Json string from a data contract class. Developed a new data-contract class by name CG_CustomerDataContract which hosts the AccountNum and CustomerGroupId fields from table "CustTable".
DataContract Class: CG_CustomerDataContract
[DataContractAttribute]
class CG_CustomerDataContract{ CustAccount custAccount; CustGroupId custGroupId; [ DataMemberAttribute('CustAccount'), SysOperationLabelAttribute(literalstr("Customer")), SysOperationHelpTextAttribute(literalstr("Customer account")) ] public CustAccount parmCustAccount(CustAccount _custAccount = custAccount) { custAccount = _custAccount; return custAccount; } [ DataMemberAttribute('custGroupId'), SysOperationLabelAttribute(literalstr("Customer group")), SysOperationHelpTextAttribute(literalstr("Customer groupId")) ] public CustGroupId parmCustGroupId(CustGroupId _custGroupId = custGroupId) { custGroupId = _custGroupId; return custGroupId; } }Runnable Class: CG_SerializeJsonFromDataContractclass CG_SerializeJsonFromDataContract{ /// <summary> /// Runs the class with the specified arguments. /// </summary> /// <param name = "_args">The specified arguments.</param> public static void main(Args _args) { CustTable custTable; CG_CustomerDataContract dataContract = new CG_CustomerDataContract(); str json; select firstonly custTable where custTable.AccountNum == "1000"; dataContract.parmCustAccount(custTable.AccountNum); dataContract.parmCustGroupId(custTable.CustGroup); json = FormJsonSerializer::serializeClass(dataContract); info(strFmt("%1", json)); } }Output: https://drive.google.com/open?id=1xMOaJr35PY3WRFm_TjdGj-1jgTglBryo
Regards,
Chaitanya Golla

Like
Report
*This post is locked for comments