Asked by:
CRM 2011 Javascript to check date set on form

Question
-
Need help with the following:
I have a follow up date on my Opportunity form that can be set to no more than 3 months from todays date. If a the date set is beyond that, then the user should be presented with a popup.
How do I accomplish this? Any help will be appreciated
Wednesday, June 6, 2012 4:19 PM
All replies
-
On your date field you could attach an on change event with the following code:
function CheckDate() { var myDate = new Date(Xrm.Page.getAttribute("your_field_name").getValue()); var date = new Date(); var month = date.getMonth() + 3; date.setMonth(month); if (myDate > date) { alert("More than 3 months out"); } }
Jason Lattimer
- Proposed as answer by JLattimerMVP, Moderator Wednesday, June 6, 2012 5:17 PM
Wednesday, June 6, 2012 5:16 PMModerator -
Excellent, just what I need - Will test later tonight and post back if all works fine
pancho15
Wednesday, June 6, 2012 5:20 PM -
Could you kindly amend the script to cater for 3 days instead of 3 months? I will need almost the same script for another form
pancho15
Wednesday, June 6, 2012 5:24 PM -
Pancho,
Try this script.
function CheckDate() { var myDate = new Date(Xrm.Page.getAttribute("your_field_name").getValue()); var date = new Date(); var day = date.getDate() + 3; date.setDate(day); if (myDate > date) { alert("More than 3 days out"); } }
I hope this helps. If my response answered your question, please mark the response as an answer and also vote as helpful.
Dimaz Pramudya | CSG (Melbourne) | http://www.xrmbits.com | dimaz@xrmbits.com If this post answers your question, please click "Mark As Answer" on the post and "Mark as Helpful"
- Proposed as answer by Dimaz Pramudya (www.xrmbits.com) Thursday, June 7, 2012 4:23 AM
Thursday, June 7, 2012 4:23 AM