Hi,
When you read any CRM DateTime value using OData Service, the value comes in “/Date(1314763200000)/“ format, which we can’t directly set to DateTime field.
Reason :-
- OData parses data in “Edm.DateTime” type
- <d:new_StartDate m:type=”Edm.DateTime”>2011-08-18T04:00:00Z</d:IBT_StartDate>
How to Type Cast to DateTime :-
- Use below code to type cast OData DateTime type (i.e., Edm.DateTime) to CRM DateTime
- var dt = ODataEntity.results[0].new_StartDate;
dt = dt.replace(“/Date(“, “”);
dt = dt.replace(“)/”, “”);
var dateValue = new Date(parseInt(dt, 10));
dateValue.setDate(dateValue.getDate());
Xrm.Page.data.entity.attributes.get(“{fld_name}”).setValue(dateValue);
Hope it helps 🙂
![[Step by Step] Beginner : Create a PCF control and add it to a custom page](https://rajeevpentyala.com/wp-content/uploads/2024/12/image-49.png)


Leave a reply to Naresh Veginati Cancel reply