locked
add days to crm date attribute using java script RRS feed

  • Question

  • Hi,

    I am updating child product records for parent opp.

    I am using java script code

    the child record date attribut should be updated by the estimated close date field value incremented by 5 days

    The problem is I can 't add days to the estimatedclose date attribute

    my code is:

    var noOfdays = 5 ;

    var

     

    d = crmForm.all.estimatedclosedate.DataValue;

     

    var newShipDate = new Date().setDate(d + noOfdays);

    The date calculation is not correct

    Thanks

    Marwa Saleh

     

     

    Thursday, May 20, 2010 5:48 PM

Answers

All replies

  • var d = crmForm.all.estimatedclosedate.DataValue;

    var newDT = d.setDays(d.getDays() +5);

    crmForm.all.yourdatefiled.DataValue  = newDT;


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Thursday, May 20, 2010 5:54 PM
  • hi,

    sorry to mark as un answer, but I tried the and doesn't work

    I am passing the new date to update web service to update the child product

     

    Thanks

    Marwa

    Thursday, May 20, 2010 7:08 PM
  • Hi

    means to  say the above doesn't  work? strange ?

    you can also  try  the below.

    var dateField = crmForm.all.your_DateField;
    var currentValue = dateField.DataValue;

    //If the user changes the date field from null to a valid date, set the
    //time portion to 8:30
    if ((currentValue != null) && (_previousValue == null)) {

    var newDate = new Date(
    currentValue.getYear(),
    currentValue.getMonth(),
    currentValue.getDate() + 5,
    8, 30);

    dateField.DataValue = newDate;
    }


    Muhammad Ali Khan
    http://malikhan.wordpress.com
    Thursday, May 20, 2010 7:16 PM
  • Hi,

    Thank you for your fast response

    I tried the code but it increment by years then i removed 8 and 30 as below


    var newDate = new Date(
    currentValue.getYear(),
    currentValue.getMonth(),
    currentValue.getDate() + 5);

    but it adds 10 days instead of 5 

    do you have any other suggestion Please?

    Thanks

    Marwa

     

    Thursday, May 20, 2010 8:30 PM
  • Minor code change for Muhammad's script:

    var d = crmForm.all.estimatedclosedate.DataValue;

    d.setDate(d.getDate() +5);

    That's all that should be needed.  The references to the setDate and getDate functions come from: http://www.w3schools.com/js/js_obj_date.asp


    Dave Berry
    Thursday, May 20, 2010 8:50 PM
    Moderator
  • Thursday, May 20, 2010 9:01 PM