Picking current date but changing when viewing the case

Discussions about CSEntry
Forum rules
New release: CSPro 8.0
tweg
Posts: 29
Joined: June 16th, 2015, 2:41 am

Picking current date but changing when viewing the case

Post 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
khurshid.arshad
Posts: 571
Joined: July 9th, 2012, 11:32 am
Location: Islamabad, Pakistan

Re: Picking current date but changing when viewing the case

Post by khurshid.arshad »

Dear Tweg;

Please use this code:

If demode()=1 then

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

else
endif;



a.
tweg
Posts: 29
Joined: June 16th, 2015, 2:41 am

Re: Picking current date but changing when viewing the case

Post by tweg »

Dear Arshad,
Thanks for your reply it worked.

Regards
Kyaw Thet
Posts: 5
Joined: May 12th, 2017, 1:32 am
Location: Myanmar

Re: Picking current date but changing when viewing the case

Post by Kyaw Thet »

It doesn't work to me.

Yours,
Kyaw Thet
Kyaw Thet
Posts: 5
Joined: May 12th, 2017, 1:32 am
Location: Myanmar

Re: Picking current date but changing when viewing the case

Post 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
sah
Posts: 97
Joined: May 28th, 2015, 3:16 pm

Re: Picking current date but changing when viewing the case

Post 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,
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Picking current date but changing when viewing the case

Post 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.
Kyaw Thet
Posts: 5
Joined: May 12th, 2017, 1:32 am
Location: Myanmar

Re: Picking current date but changing when viewing the case

Post 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
josh
Posts: 2399
Joined: May 5th, 2014, 12:49 pm
Location: Washington DC

Re: Picking current date but changing when viewing the case

Post by josh »

Yes. Edit returns an alphanumeric. If you want to store your date numeric then don't use edit:
DATE=sysdate("DDMMYYYY");
MrTaco
Posts: 128
Joined: November 18th, 2014, 1:55 am

Re: Picking current date but changing when viewing the case

Post 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
Post Reply