Skip to main content
M.Hasanin
Inspiring
April 29, 2018
Answered

How to Store the Old Date into Variable and Call it again

  • April 29, 2018
  • 2 replies
  • 2080 views

Hi Experts..

I write code in checkbox so when clicked it will show (today date) inside date field, the problem is that i want when the user uncheck the Checked box it will restore again the old date, i try to store the date many ways but the script is ignoring any variable to store the old date,, so it ends me to call the old date from another field,, but are there any way straight forward in the same code , here is my code inside ( MouseUp Event of the Checkbox) :

// Write Today Date in Georgian

//WriteTodayDate if Checked

// box is checked

if (event.target.value != "Off") {

// get todays date object

var oNow = new Date();

var sNow = util.printd("yyyy/mm/dd", oNow);

// set date now

this.getField("todaysDate").value = sNow;

} else {

// box is unchecked

//Set the Old date

var OrgDate = this.getField("PrevDate").value;

this.getField("todaysDate").value = OrgDate;

}

and Thanks in Advance for any help

This topic has been closed for replies.
Correct answer Bernd Alheit

i Used this Code ... i think my problem that i tried to save the variable in the same time to hit checkbox and this is not possible to store the old date / Pre Written Date.

  1. // Write Today Date in Georgian 
  2. //WriteTodayDate if Checked 
  3. // convert a date or time string to a date object; 
  4. var cDateFormat = "yyyy/mm/dd"; // format for date string; 
  5. // open date values; 
  6. var cOpenDate = this.getField("todaysDate").value; 
  7.  
  8. // box is checked 
  9. if (event.target.value != "Off") { 
  10.  
  11. // Today date values; 
  12. var cTodayDate = new Date(); 
  13. var oCloseDate = util.printd("yyyy/mm/dd", cTodayDate); 
  14. this.getField("todaysDate").value = oCloseDate  
  15.  
  16. } else
  17. // box is unchecked 
  18. //Set the Old date 
  19. var oOpenDate = Scand(cDateFormat, cOpenDate); 
  20. this.getField("todaysDate").value = oOpenDate 

Try this:

if (event.target.value != "Off") { 

 

// save the Old date 

this.getField("PrevDate").value = this.getField("todaysDate").value;

// get todays date object 

var oNow = new Date(); 

var sNow = util.printd("yyyy/mm/dd", oNow); 

// set date now 

this.getField("todaysDate").value = sNow; 

 

} else { 

// box is unchecked 

//Set the Old date 

var OrgDate = this.getField("PrevDate").value; 

this.getField("todaysDate").value = OrgDate; 

 

2 replies

Bernd Alheit
Community Expert
Community Expert
April 29, 2018

Where did you set the value of the field "PrevDate"?

M.Hasanin
M.HasaninAuthor
Inspiring
April 29, 2018

I duplicate the DateField (TodaysDate) and Named it (PrevDate) then i put (On Blur) action in (TodaysDate) javascript it to Give The (PrevDate) its Value :

this.getField("PrevDate").value = event.value;

This  Method Works and Everything is fine,, but i forced to Hide (PrevDate) Field, i Was Wondering if there is a Straight Forward Way in One Script

Mohammad Hasanin
Bernd Alheit
Community Expert
Community Expert
April 29, 2018

In the properties of the field you can set it as hidden.

M.Hasanin
M.HasaninAuthor
Inspiring
April 29, 2018

also i tried to re-write the code as the following but it also not working...it write only the new date but never restore the old date

// Write Today Date in Georgian

//WriteTodayDate if Checked

// convert a date or time string to a date object;

var cDateFormat = "yyyy/mm/dd"; // format for date string;

// open date values;

var cOpenDate = this.getField("todaysDate").value;

// box is checked

if (event.target.value != "Off") {

// Today date values;

var cTodayDate = new Date();

var oCloseDate = util.printd("yyyy/mm/dd", cTodayDate);

this.getField("todaysDate").value = oCloseDate

} else {

// box is unchecked

//Set the Old date

var oOpenDate = Scand(cDateFormat, cOpenDate);

this.getField("todaysDate").value = oOpenDate

}

Mohammad Hasanin