cancel
Showing results for 
Search instead for 
Did you mean: 

How to automatically set Current Date on a date field

celo_berger
Active Participant
0 Kudos

Hi everyone,

I'm creating an HR flavor using Personas 3.0 on tcode PA40, where I want to default the Start Date to be the current date in the system, but I'm struggling on how to do it.

I did find this help.sap link which does mention about using Set Current Date, but I'm unclear on how to apply this to my script.

I appreciate any feedback I can get.

Thanks,

Marcelo

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member105930
Active Participant
0 Kudos

I have done something similar, although I have not used the Onload screen event (but after seeing this thread I might give that a go.

What I have done is added a script to my start page to open PA40 and then push a script button on my main PA40 page in which the scritping is as follows:

So when the page is loaded, the original script then pushes this button (which I've hidden) which populates the date in the highlighted field.

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

You could use one of the described methods on this page and attach the script to the OnLoad screen event.

shaun_kitching
Active Contributor
0 Kudos

Hi Tamas!

I have tried using one of these methods. I have saved it as a script.

I have then edited my Flavor, selected the Date field and have assigned the above mentioned script OnLoad.

I have then saved the Flavor.

When the Flavor loads, all I get is a blank white screen with the date (and yes it is the current date!). But I want this date to appear in the date field, not just on a blank white screen and everything else disappears.

Any idea where I'm going wrong?

Thanks
Shaun

tamas_hoznek
Product and Topic Expert
Product and Topic Expert
0 Kudos

This will work as an onLoad script:


var utc = new Date().toJSON().slice(0,10);

session.findById("wnd[0]/usr/txtPersonas_147512149651572").text = utc;

(replacing the ID with your target field ID in the flavor of course)

If you need something else than UTC or in a different output format, then you need to further massage the script so it satisfies your requirement. There are a lot of other ideas on that page.

shaun_kitching
Active Contributor
0 Kudos

Thank you Tamas. I was oh so close before...just had to delete the "document.write" (that's why it was populating the entire screen and not the field).

I also wanted dd.mm.yyyy format. Here is my code incase anyone is interested:

var today = new Date();

var dd = today.getDate();

var mm = today.getMonth()+1; //January is 0!

var yyyy = today.getFullYear();

if(dd<10) {

    dd='0'+dd

}

if(mm<10) {

    mm='0'+mm

}

today = dd+'.'+mm+'.'+yyyy;

session.findById("wnd[0]/usr/ctxtSTTAG").text = today;

Obviously changing the FORMAT to whatever you want and the ID your ID.