How to set the logged in user date or date/time format with the help of client scripts?

Shantharao
Kilo Sage

Hi All,

How to set the date time with the help of client scripts?

Is it possible to ser date and time without using Ajax call in the client script?

 

Thanks

 

1 ACCEPTED SOLUTION

Shantharao
Kilo Sage

With this simple client script code we can set date and time to the Date/Time type field or variable

function onLoad() {
var dt = formatDate(new Date(), g_user_date_time_format);
alert(dt);
g_form.setValue("u_date", dt);
}

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Here's some nice reading for you:
https://www.servicenowguru.com/scripting/client-scripts-scripting/client-side-dates-in-servicenow/

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

asifnoor
Kilo Patron

Hi,

Refer to this link where i have shown how to use date validations in the client script with examples.

https://community.servicenow.com/community?id=community_article&sys_id=a26dac761b4e8010a59033f2cd4bc...

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP

Shantharao
Kilo Sage

With this simple client script code we can set date and time to the Date/Time type field or variable

function onLoad() {
var dt = formatDate(new Date(), g_user_date_time_format);
alert(dt);
g_form.setValue("u_date", dt);
}

Thanks for the solution. I am new to NOW platform and the code snippet above worked for me.