Set current date time using client script

DivyaNarayG
Tera Contributor

Hi,

We have a scenario when state changes to Assigned, the assigned date field should get update with current date time.

I am trying to on change client script with below script but it has update with incorrect format.

Please suggest.

 

if (newValue == '1')
       {
        g_form.setValue('assigned_date',Date.now());
       }
8 REPLIES 8

Hello Divya,

Regarding the time zone. First, you have to check your instance system timezone from "Basic Configuration".

Then change this script according to your timezone. For this script the time zone is "Ameria/New_York".

var today_date= new Date();
var easternTime = today_date.toLocaleString("en-US", {timeZone: "America/New_York"});


Try this and let me know if approach will work or not.

Thank you.



HI MIhir,

 

I have written the below code , but its not working

 

DivyaNarayG_0-1717509113513.png

 

Hello Divya,
Could you explain please, Do you have a problem with the date format or an incorrect date value?

 

When I tried in the background script it returned: 4 Jun

 

var today_date = new Date();
gs.info(today_date);

 

Result :
Tue Jun 04 2024 22:27:07 GMT-0700 (PDT)

When I tried in the Client script it returned: 5 Jun

 

 var today_date = new Date();
 alert(today_date);

 

 Result :

 

Wed Jun 05 2024 11:00:24 GMT+0530 (India Standard Time)

 

 

I don't know how it is returned on a different date.

Could you please explain to me, What is your exact problem with the screen short of the date?

Thank you.

Hello @DivyaNarayG 


If necessary,
 you can explicitly specify the time zone you want to use with the new Date() function by providing relevant parameters (e.g., new Date(2024, 05, 05, 12, 00, 00, UTC)).

 

If my reply helped with your issue please mark it helpful mihirlimje867_0-1717652904078.png and correct mihirlimje867_1-1717652904081.pngif your issue is resolved.

 

 By doing so you help other community members find resolved questions which may relate to an issue they're having