The days of the week on time cards should display the corresponding date based on the week start date

muralikrishns
Kilo Contributor

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!

1 ACCEPTED SOLUTION

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 + ')' ;


  }


View solution in original post

20 REPLIES 20

but In my requirement need to do with UI policies


OK. Create a UI policy with no condition statement. In the script section, check advanced and you get two script boxes.



Execute if true: place your script to add the labels .


Execute if false: leave empty (or what ever the template provides)


i did below code its not working



function onCondition() {


  function printdate()


  {


  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());


  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 + ')' ;


  }


}Timecard.PNG


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 + ')' ;


  }


Thanks Ram



i am facing one issue when i change the date in "week start on" based on this week days need to set



its not reflecting based on that can you   help me ..................


Thanks!


timecard.PNG









function onCondition(){


  printdate();


  function printdate()


  {


  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).toString();


  g_form.setLabelOf(fields[loop],frmtval);


  }


  }


  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 + ')' ;


  }


}