Since the Custom Date/Time field requires seconds and by adding the "datetimetz" as a second parameter in nlapiDateToString function, it will return a date/time with seconds value. The Help Guide documentation does not state anything about this parameter for nlapiDateToString.
Create a Custom Field with Date/Time as type
1. Navigate to Customization > Lists, Records, & Fields > Entity Fields > New
2. In the Custom Entity Field Screen, enter on the Label field "Date and Time Field" and select Date/Time on the Type field and deployed on the Customer
Create a User Event on After Record Submit function that will display a value of date and time with seconds on the custom field.
3. Navigate to Customization > Scripting > Scripts > New > Type = User Event
4. Fill out the Name and ID field
5. In the Scripts Tab > Upload the Script File below
function setTimeAfterSubmit()
{
var date_time_value = nlapiDateToString(new Date(), 'datetimetz');
nlapiSetFieldValue('DATE_TIME_FIELD',date_time_value, false);
}
4. In the Script Tab > Function > Fill Out the Function Field
5. Save and Deploy
6. In the Deployments Tab > set Execute as Admin = Checked , Deployed = Checked
Status = Released, Log Level = Error
7. In the Deployments Tab > Applies To = Customer
8. In the Deployments Tab > Audience > Roles > All Roles = Checked > Save
9. Navigate to Lists > Relationships > Customers > New, enter the necessary information and click Save
Result: Custom Date/Time Field display date/time with seconds (e.g. 2012-1-9 1:21:24 pm)
nlapiDateToString does not adjust the date and time based on the user's time zone.(Enhancement# 185661)
Using new Date() on any server side script will only return the date/time based on the Pacific Time zone.
Using new Date() on client side will return the date/time based on the user's system time (not user preference).
Using nlapiDateToString will not adjust date and time. It will simply translate the Date object to a String object.
No comments:
Post a Comment