The CreatorCon Call for Content is officially open! Get started here.

Need to display weekday name and date in MM-DD format below the day name in header.

ricksam
Giga Contributor

Hi All,

I need to develop code for below shown format.

Header.png

I got the day format using glide script and also got the date format in html. But its difficult to bind both of them in dynamic content and display.

Please suggest. I am a beginner for service now and not able to do this within timeline.

1 ACCEPTED SOLUTION

Hi Adam,



Sorry to reply late. I was so busy in work. Didn't check it.



Yes I got another way of doing this in Macro. Please reply if this is helpful. I have not tried Harish's code.



Code:-



<?xml version="1.0" encoding="utf-8" ?>


<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">



<g:evaluate>  


var days = new Array('', 'Mon', 'Tues', 'Weds', 'Thurs', 'Fri', 'Sat', 'Sun');


var months = new Array('','01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');


var dates =   new Array('','01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '28', '29', '30', '31');




var datetoday = new GlideDateTime();


var today = days[datetoday.getDayOfWeek()];



var day1name = new GlideDateTime(gs.daysAgo(1));


var day1 = days[day1name.getDayOfWeek()];


var date1= months[day1name.getMonth()]+"-"+ dates[day1name.getDayOfMonth()];



var day2name = new GlideDateTime(gs.daysAgo(2));  


var day2 = days[day2name.getDayOfWeek()];


var date2= months[day2name.getMonth()]+"-"+ dates[day2name.getDayOfMonth()];



var day3name = new GlideDateTime(gs.daysAgo(3));  


var day3 = days[day3name.getDayOfWeek()];


var date3= months[day3name.getMonth()]+"-"+ dates[day3name.getDayOfMonth()];



var day4name = new GlideDateTime(gs.daysAgo(4));  


var day4 = days[day4name.getDayOfWeek()];


var date4 = months[day4name.getMonth()]+"-"+ dates[day4name.getDayOfMonth()];



var day5name = new GlideDateTime(gs.daysAgo(5));  


var day5 = days[day5name.getDayOfWeek()];


var date5=months[day5name.getMonth()]+"-"+ dates[day5name.getDayOfMonth()];



var day6name = new GlideDateTime(gs.daysAgo(6));  


var day6 = days[day6name.getDayOfWeek()];


var date6= months[day6name.getMonth()]+"-"+ dates[day6name.getDayOfMonth()];



var day7name = new GlideDateTime(gs.daysAgo(7));  


var day7 = days[day7name.getDayOfWeek()];


var date7=months[day7name.getMonth()]+"-"+ dates[day7name.getDayOfMonth()];



</g:evaluate>  



<br/>


${day1}


${date1}<br/>


${day2}


${date2}<br/>


${day3}


${date3}<br/>


${day4}


${date4}<br/>


${day5}


${date5}<br/>


${day6}


${date6}<br/>


${day7}


${date7}<br/>



</j:jelly>


View solution in original post

18 REPLIES 18

Could you confirm one thing how your geting dynamic date based upon that you can do code change



var answer = '12-14@@12-15@@12-16@@12-17@@12-18@@12-19@@12-20'; //here i hard coded the date but if your asking you need dynamic get the data and assign it to answer variable.




Regards,


Harish.


I'm getting the data but not in proper format. Also once I'm reaching the starting of array to get Daynames then it's giving as undefined. Please help.



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">






<html>


<script>


var now = new Date();


var days = new Array('Sun','Mon','Tues','Weds','Thurs','Fri','Sat');


var months = new Array('01','02','03','04','05','06','07','08','09','10','11','12');


var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();


function fourdigits(number){


      return (number < 1000) ? number + 1900 : number;


                                        }


today = days[now.getDay()] + " " +


              months[now.getMonth()] + "-" +


              date ;


document.write(today);




yesterday = days[now.getDay()-1] + " " +


              months[now.getMonth()] + "-" +


              [(now.getDate()-1)] ;


document.write(yesterday);




day2 = days[now.getDay()-2] + " " +


              months[now.getMonth()] + "-" +


              [(now.getDate()-2)] ;


document.write(day2);




day3 = days[now.getDay()-3] + " " +


              months[now.getMonth()] + "-" +


              [(now.getDate()-3)] ;


document.write(day3);




day4 = days[now.getDay()-4] + " " +


              months[now.getMonth()] + "-" +


              [(now.getDate()-4)] ;


document.write(day4);




day5 = days[(now.getDay()-5)] + " " +


              months[now.getMonth()] + "-" +


              [(now.getDate()-5)] ;


document.write(day5);


</script>




</html>



Also i got below format to do all the works but I'm not able to get the output. If you can format it for me and give the answer, it will be a great help.



<script>
function displayDate(inti)
{
var now = new Date();

var days = new Array('Sun', 'Mon', 'Tues', 'Weds', 'Thurs', 'Fri', 'Sat');

var months = new Array('01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12');

var date = ((now.getDate() < 10) ? "0" : "") + now.getDate();

function fourdigits(number) {

return (number < 1000) ? number + 1900 : number;

}

today = days[now.getDay()] + " " +

months[now.getMonth()] + "-" +

date;

// document.write(today);



yesterday = days[now.getDay() - inti] + " " +

months[now.getMonth()] + "-" +

[(now.getDate() - inti)];


Send me that screen shot pelase.


The requirement screenshot is above. The code snippet I gave. I'm not sure which screenshot you require.


Hi Ricky,



                    I have written the code by using javascript. It will display details below .




Check here i have done in demo.


https://demo011.service-now.com/login.do



Username and Password : admin



Once you login click this link : ServiceNow