-
JavaScript: Working with Dates Returned from Web Service Calls
Revised Thursday, July 11th.
I’ve been doing a lot of work recently using JavaScript to retrieve data from CRM via web service calls. One of the issues I ran into is the date format returned by CRM is in Coordinated Universal Time ( UTC ) which is not the same format most programming languages use. This leads to conversion issues or programming exceptions.
To work around any issues, I created a JavaScript function that allows me to parse the UTC date and time string and return a JavaScript Date value.
At this point, the function is only concerned with the date, but if you need the time, you can modify the function to add those additional parameters to the new Date() line.
For more information on the JavaScript Date object, please visit the following link.
function ConvertDateFromUTC(startDate){// UTC time formatted string//2009-03-25T09:30:00-00:00 // 1 2 //1234567890123456789012345var year = parseInt(startDate.substr(0, 4),10);var month = parseInt(startDate.substr(5, 2),10);var day = parseInt(startDate.substr(8, 2),10);var hour = parseInt(startDate.substr(11, 2),10);var min = parseInt(startDate.substr(14, 2),10);return new Date(year, month - 1, day);
}
July 11th: Corrected issues as pointed out by Moti, in the comments.
Making It Work
In this example, I’m using the excellent CrmService library released by Ascentium, to retrieve values from a contact.
var oService = new Ascentium_CrmService();
var asCols = ["fullname",
"address1_postalcode","address1_city","address1_stateorprovince","birthdate"];var beRetrievedContact =oService.Retrieve("contact",crmForm.all.customerid.DataValue[0].id,
asCols);
var birthDateString = beRetrievedContact.attributes["birthdate"].value;
var birthDate = new Date(ConvertDateFromUTC(birthDateString));
Customization, Dynamics CRM 1,211 views -
What keeps your people from selling?
This is one of the primary questions I ask when starting the discovery phase of a CRM implementation.
Why is this important?
This question is important to everyone because the more distractions that can be eliminated from the life of a sales person, the more time they have to sell. Hopefully, the following equation fits into your organization:
And more sales generally translates into more money – for everyone.
How do I make a difference?
During your discovery process, ask these simple questions:
- What types of reports are your sales people required to produce?
- Is any data collected and returned to anyone in an Excel worksheet?
- What procedures or processes do your salespeople perform repetitively?
Collect these answers, then review the native capabilities found with Dynamics CRM. Implement out of the box solutions when you can and create custom solutions when you must.
Your changes don’t need to occur all at once, and as always, keep the users involved in the process so they can see where you’re going and how the changes will help them sell.
Dynamics CRM 587 views




