- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2016 02:26 AM
To further increase usability on time entry, let's have a way to display the actual date for the days of the week on time cards. There is a field for each day of the week.
i need to write a ui policy for that displays the correct date next to each day of the week field
This can key off of the week start date. To display, let's update the field lables (g_form.setLabel) to match the following example: "Tuesday (7/5/2016)"
Thanks!
Solved! Go to Solution.
- Labels:
-
Team Development
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-13-2016 08:16 AM
Hi Murali,
You need to call "printdate" function in onCondition() function. I put few alerts as well in code now. If everything is good, remove those alerts. Or else let us know, what are the alerts you are getting.
function onCondition() {
printdate();
function printdate()
{
alert("Inside printdate function");
var g_form = new GlideForm();
var fields = ["sunday","monday","tuesday","wednesday","thursday","friday","saturday"];
for(var loop = 0 ; loop < 7 ; loop++)
{
var dtDate = new Date();
dtDate.setDate(dtDate.getDate() + loop - dtDate.getDay());
var frmtval = getDateLabel(dtDate);
alert(frmtval);
g_form.setLabelOf(fields[loop],frmtval);
}
}
function getDateLabel(dt)
{
alert("inside getDate label function");
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var fmt = dt.getMonth()+1 + "/" + dt.getDate() + "/" + dt.getFullYear();
return weekday[dt.getDay()] + '(' + fmt + ')' ;
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2016 05:43 AM
The HelloWorld example in the GlideAjax page is a great example to start from.
Use an onChange client script (that also runs onLoad) to watch for changes on your start week on date field. The client script calls the server via GlideAjax to calculate the dates for the various fields. It can return multiple responses at once, to which the client script's callback function can apply them to the labels using g_form.setLabelOf().
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2016 05:55 AM
Interesting question though it involves mostly javascript, You can have a "onload" client script, and write like following. You need to call printdate function and change the fields array with your actual field names.
function printdate()
{
var g_form = new GlideForm();
var fields = ["field1","field2","field3","field4","field5","field6","field7"];
for(var loop = 0 ; loop < 7 ; loop++)
{
var dtDate = new Date();
dtDate.setDate(dtDate.getDate() + loop - dtDate.getDay());
g_form.setLabelOf(fields[loop],getDateLabel(dtDate));
}
}
function getDateLabel(dt)
{
var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var fmt = dt.getMonth()+1 + "/" + dt.getDate() + "/" + dt.getFullYear();
return weekday[dt.getDay()] + '(' + fmt + ')'
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-11-2016 06:12 AM
Thanks Ram. Great idea. I recommend changing this to an onChange client script as the "start week on" field could change, and you want to keep your labels up to date with that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2016 05:53 AM
is it possible to write UI Policy

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-12-2016 05:54 AM
It is, but I don't see that as a good fit here. A UI policy is great for "if this then that" scenarios. An onChange client script is better for "this field value changed, now go do that"