How to auto populate catalog item variable with current date

WP2
Kilo Guru

Hi ALL,

I have a variable with Date Type and I want the variable to auto populate current date. I used onChange client script with below script but no date populated. Could you please help with a script to achieve this requirement. Thank you.

var dFormat = g_user_date_format;

var tdayDate = formatDate(new Date(),dFormat);


g_form.setValue('todayDate', tdayDate);

1 ACCEPTED SOLUTION

Utpal Dutta1
Mega Guru

Hey Rich,

 

Go to variable dictionary (right click on the variable) and in default value write this: javascript:gs.nowDateTime()

 

 

If it works the please mark my answer Correct and Helpful.

 

 

Thanks and Regards:

Utpal Dutta 

View solution in original post

10 REPLIES 10

Utpal Dutta1
Mega Guru

Hey Rich,

 

Go to variable dictionary (right click on the variable) and in default value write this: javascript:gs.nowDateTime()

 

 

If it works the please mark my answer Correct and Helpful.

 

 

Thanks and Regards:

Utpal Dutta 

Thanks Utpal. It worked for the date. Can you guide me with populatinge the "requestor's TITLE" to a single line text type? Usually there is a field on the user table called title with user's title info. Thanks

Hi,

for logged in user title you need to use this; in the default value of that variable

javascript: gs.getUser().getRecord().getValue('title');

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi. I tried this script but its not populating.