Page 1 of 1

Updating date fields on priority field change

Posted: 12 Apr 2016
by Jaydius
Im trying to adjust two date fields when a choice field is changed ('Priority'). Based on the radio button choice, the dates need to be calculated using the 'Reportedon' date/time field, then updated in their respective fields. Heres my code:

fd.field('Priority').change(function(){
var duedate = new Date();
var shedate = new Date();
var orgdate = fd.field('Reportedon').value();

if (fd.field('Priority').value() == '0') {
duedate.setDate(orgdate + 1);
shedate.setDate(orgdate + 1);
} else if (fd.field('Priority').value() == '1') {
duedate.setDate(orgdate + 7);
shedate.setDate(orgdate + 7);
} else if (fd.field('Priority').value() == '2') {
duedate.setDate(orgdate + 14);
shedate.setDate(orgdate + 7);
} else if (fd.field('Priority').value() == '3') {
duedate.setDate(orgdate + 30);
shedate.setDate(orgdate + 14);
} else if (fd.field('Priority').value() == '4') {
duedate.setDate(orgdate + 182);
shedate.setDate(orgdate + 152);
} else if (fd.field('Priority').value() == '5') {
duedate.setDate(orgdate + 365);
shedate.setDate(orgdate + 305);
} else {
}
fd.field('NextDue').value(duedate);
fd.field('NextScheduled').value(shedate);
});

Appreciate any help.

Re: Updating date fields on priority field change

Posted: 13 Apr 2016
by rostislav
This should help you:

Code: Select all

var duedate = fd.field('Reportedon').control('getDate');
duedate.setDate(duedate.getDate() + 1); //increment days by one

Re: Updating date fields on priority field change

Posted: 13 Apr 2016
by Jaydius
Perfect. Thanks for your help.