- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 01:08 AM
Hello Friends,
Could you please help us here, we have one schedule job that runs on daily basis and inside this scheduled job we have condition to trigger notification only on Wednesday. So, to achieve this we have write a script that will tell us the day of the week and it’s return a number for a day of the week.
But, I need some confirmation, is this script giving us correct results?
Please provide yours comments on this.
var todayDateTime = new GlideDateTime(gs.nowDateTime());
var integerValForToday = todayDateTime.getDayOfWeekLocalTime();
gs.print(integerValForToday);
gs.print(todayDateTime.getLocalDate());
it’s return below result :
*** Script: 4
*** Script: 2018-05-24
Thanks, Basant
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 02:03 AM
Hi Basantsoni,
Update your script as below:
var todayDateTime = new GlideDateTime(gs.nowDateTime());
var integerValForToday = todayDateTime.getDayOfWeekLocalTime();
var jsonObj = '{"1":"Monday","2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","7":"Sunday"}';
var parser = new JSONParser();
var parsedData = parser.parse(jsonObj);
var dayOfWeek = parsedData[integerValForToday];
the highlighted variable will give you the value such as Monday or Tuesday etc
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 01:33 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 01:37 AM
you can try like this.
<script>
function myFunction() {
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var n = weekday[d.getDay()];
document.getElementById("demo").innerHTML = n;
}
</script>
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-25-2018 02:03 AM
Hi Basantsoni,
Update your script as below:
var todayDateTime = new GlideDateTime(gs.nowDateTime());
var integerValForToday = todayDateTime.getDayOfWeekLocalTime();
var jsonObj = '{"1":"Monday","2":"Tuesday","3":"Wednesday","4":"Thursday","5":"Friday","6":"Saturday","7":"Sunday"}';
var parser = new JSONParser();
var parsedData = parser.parse(jsonObj);
var dayOfWeek = parsedData[integerValForToday];
the highlighted variable will give you the value such as Monday or Tuesday etc
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader