Change the date format for one particular field on a record producer (dd/mm/yyyy).

Leo25
Kilo Contributor

A record producer (Employment Verification Letters) has one particular field (Travel Date) where, once the date is selected, the format needs to appear UK style (dd/mm/yyyy). I only want to change the date format for this particular field, so I don't want to change the system settings. Is there a variable attribute I can use so the date shows up like that when selected?

1 ACCEPTED SOLUTION

Sumanth16
Kilo Patron

Hi,

 

find_real_file.png

 

find_real_file.png

 

var inputFormat1 = '11/29/2019';

 

function convertDate(inputFormat ) {

function pad(s) {

return (s < 10) ? '0' + s : s; }

var d = new Date(inputFormat);

 

return [ pad(d.getDate()),pad(d.getMonth()+1),  d.getFullYear()].join('/');

}

gs.log(convertDate(inputFormat1 ))

 

 

I ran this script in background script and it is converting date into required format.I think , you need to write this code in script include and populate this value into field using client script.

 

Please mark it as helpful if it helps.

 

Thanks,
Sumanth

 

View solution in original post

3 REPLIES 3

Mark Roethof
Tera Patron
Tera Patron

Hi there,

What are you doing with this particular field on the Record Producer? And with field you actually mean variable? Is it just a loose variable, or do you also use it to map it against a field? Should the variable also be changeable or read-only?

If it's just a loose variable and read-only, you could think of having a string type variable, and just reformat the date.

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

This variable will be mapped to the case form. So it can't be a loose variable. 

Sumanth16
Kilo Patron

Hi,

 

find_real_file.png

 

find_real_file.png

 

var inputFormat1 = '11/29/2019';

 

function convertDate(inputFormat ) {

function pad(s) {

return (s < 10) ? '0' + s : s; }

var d = new Date(inputFormat);

 

return [ pad(d.getDate()),pad(d.getMonth()+1),  d.getFullYear()].join('/');

}

gs.log(convertDate(inputFormat1 ))

 

 

I ran this script in background script and it is converting date into required format.I think , you need to write this code in script include and populate this value into field using client script.

 

Please mark it as helpful if it helps.

 

Thanks,
Sumanth