Posts Tagged ‘/Date’

ADX/Dynamics Portals – Date field custom validation using JScript

April 6, 2019 1 comment

Other day, In one of our Portal Web Form step, we got a requirement to validate ‘Date Of Birth’ where the value should not be  the future date.

We can achieve this by adding a custom validator using JScript and register in your ‘Web Form Step’.

Below is the JScript code snippet which you need to paste in your Web Form Step’s ‘Custom JavaScript’ control.



  • In below script replace the ‘new_dateofbirth’ with your field’s schema name.
  • ‘new_dateofbirth_label‘ is the label of the DOB field on your Web Form Step.

$(document).ready(function () {
if (typeof (Page_Validators) == ‘undefined’) return;
// Create new DOB validator
var dobValidator = document.createElement(‘span’); = “none”; = “dobValidator”;
dobValidator.controltovalidate = “new_dateofbirth”;
dobValidator.errormessage = “<a href=’#new_dateofbirth_label’>Date of birth should be in past.</a>”;
dobValidator.validationGroup = “”;
dobValidator.initialvalue = “”;
dobValidator.evaluationfunction = function () {
var dobValue = $(“#new_dateofbirth”).val();
var dob=new Date(dobValue);
var today = new Date();
if (dob > today) {
return false;
return true;
// Add the dobValidator to Web Page’s validators array
// Attach event handler of the validation summary link
$(“a[href=’#new_dateofbirth_label’]”).on(“click”, function () {  scrollToAndFocus(‘new_dateofbirth_label’,’new_dateofbirth’);

alert(“Error during DOB validation  – “+e.description);

  • Save the Web Form Step and test in portal.
  • If you try to save DOB with future date. It shows warning in the banner as below:


  • Click on the message and it will take you to the DOB control.

Refer my other article to get familiar with Portal syntax’s.





Type-cast OData Service Datetime field in crm 2011

August 21, 2011 10 comments


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));

Hope it helps 🙂