SBM JavaScript Library Guide → JavaScript Examples → Changing Field Properties Based on Date Change
To recreate these examples, your application should contain the following fields and they should be added to your custom form:
Field type |
Database name |
Display name |
Values |
---|---|---|---|
Date/Time |
DUE_DATE |
Due Date |
On the Options tab, select Date Only. |
User |
EMRG_APPROVER |
Emergency Approver |
Users assigned to roles specified for this field or added as values for the field in SBM Application Administrator. |
Text |
EMRG_REASON |
SOW Number |
Specified by users. |
In this example, when users specify a value in the Due Date field that is fewer than seven days from the current date, the Emergency Approver and Emergency Reason fields are set as required. If the Due Date field value is more than seven days past the current date, the Emergency Approver and Emergency Reason fields are removed from the form. If the due date is past January 1, 2015, users are informed that the due date is too far in the future.
function DueDateChanged() { var text = GetFieldValue("DUE_DATE"); var DueDate = new Date(); DueDate.setTime(Date.parse(text)); var NextWeek = new Date(); NextWeek.setDate(NextWeek.getDate()+7); if (DueDate < NextWeek) { MakeFieldRequired("EMRG_APPROVER", true); MakeFieldRequired("EMRG_REASON", true); } else { HideField("EMRG_APPROVER"); HideField("EMRG_REASON"); } var FixedDate = new Date(); FixedDate.setFullYear(2015,1,1); if (DueDate > FixedDate) { alert('Date too far in the future!'); } } AddChangeCallback("DUE_DATE", DueDateChanged);
Copyright © 2007–2016 Serena Software, Inc. All rights reserved.