Using client Script set Date/Time = Current Date/Time

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2010 11:38 AM
Please can someone let me know how to do this?
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2010 12:34 PM
malan,
Try this UI policy instead of client script,
Run script :true
On Load :true
Execute if true:
function onCondition() {
g_form.setValue('sys_created_on', new Date());
var currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
if (month < 10){
month = "0" + month;
}
if (minutes < 10){
minutes = "0" + minutes;
}
if (seconds < 10){
seconds = "0" + seconds;
}
g_form.setValue('sys_created_on', month + "-" + day + "-" + year + " " + hours + ":" + minutes + ":" + seconds);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2010 03:18 PM
Very cool. Thanks.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-17-2024 09:00 AM
this can be simplified even further

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-26-2010 03:28 PM
Perhaps this should go on a new thread but here's the remaining issue I'm running into:
So lets say I have a change request. And let's say the change request is changed to a closed state. Then I want to update the closed date and default it to the current date/time.
The script you provided sets the date/time beautifully. However, it is doing it every time even if the closed_date is already populated. I only want it to occur if the closed date is empty.
So I set the field condition with ORs to check if the change request state is "closed complete" or "Closed incompete". And the script fires - all is good.
Now I want to add the caveat that only do this if closed_date is empty. I tried adding it as an AND but that doesnt work as there is already an OR condition.
Then I tried to check the "closed_at (closed date)" inside the script for null but it cannot find the variable name since it does not have visibility to the variable name.
Here is the script - any advice is appreciated:
function onCondition() {
alert(closed_at); /////////// this is where the javascript errors out as it can't see closed_at.
if(closed_at == null)
{
g_form.setValue('closed_at', new Date());
var currentTime = new Date();
var year = currentTime.getFullYear();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var hours = currentTime.getHours();
var minutes = currentTime.getMinutes();
var seconds = currentTime.getSeconds();
if (month < 10){
month = "0" + month;
}
if (minutes < 10){
minutes = "0" + minutes;
}
if (seconds < 10){
seconds = "0" + seconds;
}
g_form.setValue('closed_at', month + "-" + day + "-" + year + " " + hours + ":" + minutes + ":" + seconds);
}
}