toLocaleDateString is not working in server side script

aikotoba
Tera Guru

Hi
We need to convert a date to Japanese calendar.
On the client side, dt.toLocaleDateString('ja-JP-u-ca-japanese',{era: 'long'}) works and converts the date to the Japanese calendar without any problem, but
However, the business rule does not work well.
Doesn't it work on the server side?
Please help.

function onChange(control, oldValue, newValue, isLoading) {
	if (isLoading)
        return;

    if (newValue == "") {
        g_form.clearValue("end_date_japanese");
        return;
    }
	;
	var dt = new Date(newValue);
	var japaneseDate = dt.toLocaleDateString('ja-JP-u-ca-japanese',{era: 'long'})
	g_form.setValue("end_date_japanese",japaneseDate);
}

 

 

1 ACCEPTED SOLUTION

aikotoba
Tera Guru

toLocaleDateString does not seem to be supported
Created a custom Japanese calendar conversion script

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @aikotoba ,

You will need to use this script instead of toLocaleDateString to get the same functionality as per your requirement, just change the code as per your req:

https://community.servicenow.com/community?id=community_question&sys_id=02650a271b664c90fff162c4bd4bcb10

 

Mark my answer correct & Helpful, if Applicable.

Thanks,

Sandeep

Jorn van Beek
Tera Guru

Can you add the script you use? The current script you added is a client side script. if you are using this in a business rule it will not work.

I wrote the following, but the invalid date will be set value.

var date = current.date_field;
var dt = new Date(date);

var japaneseDate = dt.toLocaleDateString('ja-JP-u-ca-japanese',{era: 'long'});
current.japanese_date = japaneseDate;

what kind of field is "current.japanese_date"? Are you sure the variable japaneseDate has the correct value? and correct value type expected by the current.japanese_date field