web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :

Serializing and Deserializing Json for date and datetime values in D365FO

Chaitanya Golla Profile Picture Chaitanya Golla 17,225

Hi,

In this post we will see the process of serializing and deserializing Json for data and datetime values. For demo purpose, I have chosen today() and getSystemDateTime() functions.

Runnable class: CG_JsonDateTimeFunctions

class CG_JsonDateTimeFunctions
{       
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {     
        str dateStrValue, dateTimeStrValue, timeStrValue;
        date        dateValue;
        utcdatetime datetimeValue;
        UTCTimestamp timeValue;
 
        dateStrValue = FormJsonSerializer::serializePrimitive(today());
        Info(strFmt("Date in string format: %1", dateStrValue));
       
        dateValue = FormJsonSerializer::deserializeValue(Types::Date, dateStrValue);
        Info(strFmt("Date: %1", dateValue));
 
        dateTimeStrValue = FormJsonSerializer::serializePrimitive(DateTimeUtil::getSystemDateTime());
        Info(strFmt("DateTime in string format: %1", dateTimeStrValue));
       
        datetimeValue = FormJsonSerializer::deserializeValue(Types::UtcDateTime, dateTimeStrValue);
        Info(strFmt("DateTime: %1", datetimeValue));     
    }
 
}

 

Output: https://drive.google.com/open?id=13tniapm_enHTvqqZYBgIz-60j-I0GApu

Regards,

Chaitanya Golla

Comments

*This post is locked for comments