Page 1 of 2

Picking current date but changing when viewing the case

Posted: December 5th, 2016, 4:03 am
by tweg
Dear all,

I have used the following logic to pick the current date for interview date automatically

onfocus
$=edit("99/99/99",sysdate("DDMMYY"));

Then problem is that when viewing the record or modifying on a different day, the date changes to that day's date. How can I fix this?

Regards

Re: Picking current date but changing when viewing the case

Posted: December 5th, 2016, 7:29 am
by khurshid.arshad
Dear Tweg;

Please use this code:

If demode()=1 then

$=edit("99/99/99",sysdate("DDMMYY"));

else
endif;



a.

Re: Picking current date but changing when viewing the case

Posted: December 5th, 2016, 1:43 pm
by tweg
Dear Arshad,
Thanks for your reply it worked.

Regards

Re: Picking current date but changing when viewing the case

Posted: June 15th, 2017, 6:13 am
by Kyaw Thet
It doesn't work to me.

Yours,
Kyaw Thet

Re: Picking current date but changing when viewing the case

Posted: June 15th, 2017, 6:34 am
by Kyaw Thet
Dear Arshard,

What wrong to me? This logic not working.
How to do that?

PROC DATE
onfocus
iF DATE=edit("99/99/9999",sysdate("DD/MM/YYYY"));
else
endif;


Yours,
Kyaw Thet
Myanmar

Re: Picking current date but changing when viewing the case

Posted: June 15th, 2017, 7:59 am
by sah
another way to code is :


PROC DATE
onfocus
if demode ()= 1 then
DATE=edit("99/99/9999",sysdate("DD/MM/YYYY"));
endif;


I am wondering why you are using the on focus, instead of Preproc,

Re: Picking current date but changing when viewing the case

Posted: June 15th, 2017, 8:23 am
by josh
As others have mentioned, this should be done in the preproc, not in the onfocus. The general rule is that anything that has to do with setting the value of the field is done in the preproc and anything that has to do with setting the question text and/or value set is done in onfocus.

Another alternative is to use check if the field is already filled in rather than using demode:
PROC DATE
preproc
if $ = "" then
    $=
edit("99/99/99",sysdate("DDMMYY"));
endif;
The difference is that this will only set the field value once so even if you have a partially saved case and you return to the field while still in add mode the value will not change.

Re: Picking current date but changing when viewing the case

Posted: June 16th, 2017, 6:17 am
by Kyaw Thet
Dear all,

preproc
if demode ()= 1 then
DATE=edit("99/99/9999",sysdate("DD/MM/YYYY"));
endif;

I have to change the numeric to alpha (Date).

Thanks You for the guide & help.

Kyaw Thet
Myanmar

Re: Picking current date but changing when viewing the case

Posted: June 16th, 2017, 7:46 am
by josh
Yes. Edit returns an alphanumeric. If you want to store your date numeric then don't use edit:
DATE=sysdate("DDMMYYYY");

Re: Picking current date but changing when viewing the case

Posted: June 16th, 2017, 1:22 pm
by MrTaco
Hi

But how do I restrict it from changing if it has been entered

Code: Select all

preproc
// Fill in interview date automatically based on current date
$ = sysdate("YYYYMMDD");
It's numeric not Alphanumeric
Thanks