コミュニティアチーブメントバーを展開する。

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

この会話は、活動がないためロックされています。新しい投稿を作成してください。

解決済み

Auto calculate end date based on start date

Avatar

Level 5

I have a date field named dateStart and a date field named dateEnd.

The dateEnd field needs to automatically fill with the date that is 90 days after the dateStart field, which the user enters.

 

I've tried different options and never get it right.  Can someone please provide a sample of the code to accomplish this?

1 受け入れられたソリューション

Avatar

正解者
Community Advisor

From the dateEnd field in your form, remove validation pattern and make the field protected/readOnly instead of calculated.

 

I have modified the script as per your date fields format:

 

var dtStart = util.scand("yy-mm-dd", this.rawValue);
var dtEnd = new Date(dtStart.getFullYear(), dtStart.getMonth(), dtStart.getDate() +90,0,0,0,0);
var yy = dtEnd.getFullYear().toString();
var mm = (dtEnd.getMonth()+1).toString();
var dd = dtEnd.getDate().toString();
dateEnd.rawValue = (mm[1]?mm:"0"+mm[0]) + "/" +(dd[1]?dd:"0"+dd[0]) + "/" + yy[2]+ yy[3];

元の投稿で解決策を見る

4 返信

Avatar

Community Advisor

Add below code snippet in the start Date exit event:

 

var startDate= util.scand("yyyy-mm-dd", this.rawValue);
var endDate = new Date(startDate.getFullYear(), startDate.getMonth(), startDate.getDate() +90, 0, 0, 0, 0);
var yyyy = endDate.getFullYear().toString();
var mm = (endDate.getMonth()+1).toString();
var dd = endDate.getDate().toString();
endDateField.rawValue = yyyy + "-" + (mm[1]?mm:"0"+mm[0]) + "-" +(dd[1]?dd:"0"+dd[0]);

Avatar

Level 5

Thanks Vijay but I can't get it to work.  Here's the file.  Maybe that will help. The fields in question have been highlighted.

Avatar

正解者
Community Advisor

From the dateEnd field in your form, remove validation pattern and make the field protected/readOnly instead of calculated.

 

I have modified the script as per your date fields format:

 

var dtStart = util.scand("yy-mm-dd", this.rawValue);
var dtEnd = new Date(dtStart.getFullYear(), dtStart.getMonth(), dtStart.getDate() +90,0,0,0,0);
var yy = dtEnd.getFullYear().toString();
var mm = (dtEnd.getMonth()+1).toString();
var dd = dtEnd.getDate().toString();
dateEnd.rawValue = (mm[1]?mm:"0"+mm[0]) + "/" +(dd[1]?dd:"0"+dd[0]) + "/" + yy[2]+ yy[3];

Avatar

Level 5

Perfection!  Thank you so much!!  This issue is solved!