admin管理员组文章数量:1353897
I am trying to pull out a date from one field, modify that date and set that value into another, here is my code:
var startDate = Xrm.Page.getAttribute('new_startdate').getValue();
var expiryDate = startDate.getDate()+3; //Add 3 days
var expiryField = Xrm.Page.getAttribute('new_expirydate').setValue(expiryDate);
Can someone explain what I'm doing wrong? I've been at this for a while now and I fear I'm missing something blatently obvious..
Thanks in advance.
EDIT;
When the script fires, 1/1/1970 is set in the expiry field.
I am trying to pull out a date from one field, modify that date and set that value into another, here is my code:
var startDate = Xrm.Page.getAttribute('new_startdate').getValue();
var expiryDate = startDate.getDate()+3; //Add 3 days
var expiryField = Xrm.Page.getAttribute('new_expirydate').setValue(expiryDate);
Can someone explain what I'm doing wrong? I've been at this for a while now and I fear I'm missing something blatently obvious..
Thanks in advance.
EDIT;
When the script fires, 1/1/1970 is set in the expiry field.
Share Improve this question edited Jan 11, 2013 at 13:34 Jack Nutkins asked Jan 11, 2013 at 12:54 Jack NutkinsJack Nutkins 1,5555 gold badges38 silver badges73 bronze badges 02 Answers
Reset to default 4this should work
var startDate = Xrm.Page.getAttribute('new_startdate').getValue();
var expiryDate = new Date();
expiryDate.setDate(startDate.getDate()+3); //Add 3 days
var expiryField = Xrm.Page.getAttribute('new_expirydate').setValue(expiryDate);
Your problem is that the function getDate()
returns the day of the month. So the result of
var startDate = new Date("January 11, 2013");
var expiryDate = startDate.getDate()+3;
would be the number 14.
I assume that this gets converted to a Date using the Date(milliseconds) overload which represents
Integer value representing the number of milliseconds since 1 January 1970 00:00:00 UTC (Unix Epoch).
Therefore you see the this value.
So, the solution which lazarus has posted shows the correct approach.
本文标签: CRM 2011 JavaScriptModify Date From One Field And Set To AnotherStack Overflow
版权声明:本文标题:CRM 2011 JavaScript - Modify Date From One Field And Set To Another - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743940749a2565515.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论