Answered by:
crm 2011 javascript to set time in datetime field on change

Question
-
function setDateTime(fieldName, theHour, theMinute) { var theDateField = Xrm.Page.getAttribute(fieldname); if (theDateField.getValue() == null) { theDateField.setValue(new Date()); } theDateField.setValue(theDateField.getValue().setHours(theHour, theMinute, 0)); } /*--------------------------------------------------------------------------*/ function setOpportunityGoLiveDate { setDateTime("new_golivedate",12,00); //set time portion of date event to noon } /*--------------------------------------------------------------------------*/
Using the code above to set the time portion of the datetime field to fix a utc issue for a date only field I continue to get an
error that the function "setOpportunityGoLiveDate" is undefined. Can anyone assist?
Monday, January 5, 2015 9:53 PM
Answers
-
Hello,
I believe you forgot to add brackets to declaration of a function like:
function setOpportunityGoLiveDate() { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
instead of
function setOpportunityGoLiveDate { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blog- Proposed as answer by Mohd Saad Tuesday, January 6, 2015 5:02 AM
- Marked as answer by JenniferNHS Tuesday, January 6, 2015 3:06 PM
Monday, January 5, 2015 10:40 PMModerator -
you are missing the () after the function name, so it will be:
function setOpportunityGoLiveDate() { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Mohd Saad Tuesday, January 6, 2015 5:02 AM
- Marked as answer by JenniferNHS Tuesday, January 6, 2015 3:06 PM
Monday, January 5, 2015 10:41 PM
All replies
-
Hello,
I believe you forgot to add brackets to declaration of a function like:
function setOpportunityGoLiveDate() { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
instead of
function setOpportunityGoLiveDate { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
Dynamics CRM MVP/ Technical Evangelist at SlickData LLC
My blog- Proposed as answer by Mohd Saad Tuesday, January 6, 2015 5:02 AM
- Marked as answer by JenniferNHS Tuesday, January 6, 2015 3:06 PM
Monday, January 5, 2015 10:40 PMModerator -
you are missing the () after the function name, so it will be:
function setOpportunityGoLiveDate() { setDateTime("new_golivedate",12,00); //set time portion of date event to noon }
My blog: www.crmanswers.net - Rockstar 365 Profile
- Proposed as answer by Mohd Saad Tuesday, January 6, 2015 5:02 AM
- Marked as answer by JenniferNHS Tuesday, January 6, 2015 3:06 PM
Monday, January 5, 2015 10:41 PM -
Oh my gosh I stared at that for hours looking at each part of the code and still didnt see it. Also had a lower case N in the first function that needed to be a capital. Once that was fixed it works like a charm. Thanks much Andrii and Guido.Tuesday, January 6, 2015 3:07 PM