To deserialize field value from the JSON file in D365FO we need to use FormJsonSerializer class and deserializeValue method.
If you working with the custom service the date and enum type fields makes a problem because we are getting data in string format.
So need to create a string field as a parm method in contract class and while updating the data need to do the conversion.
Date:
Transdate date = FormJsonSerializer::deserializeValue(Types::Date, dateStrValue//contract.parmDate());
UtcDateTime:
TransdateTime dateTime = FormJsonSerializer::deserializeValue(Types::UtcDateTime, dateTimeStrValue//contract.parmDateTime());
Some times we need to store date value in string.
Transdate transDate = dateStr ? System.DateTime::Parse(dateStr) : Global::dateNull();
Enum:
Gender gender= FormJsonSerializer::deserializeValue(Types::Enum, contract.parmGender(), enumNum(Gender));
// contract.parmGender() need to get AOT element name (not lable).
Keep Daxing!!
No comments:
Post a Comment