- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 12:54 PM
Hello all,
I'm still very new to ServiceNow and I'm trying to figure out how to assign colors to schedules I add to a 'Schedule Page' based on the 'Type' of that schedule.
For instance, to add a schedule to my schedule page, I'm doing the following based on the 'Name' of the schedule containing a certain substring:
g.initialize();
g.addQuery('name', 'CONTAINS', substring);
g.query();
while (g.next()) {
schedulePage.addSchedule(g.sys_id, #1f2624, null, true);
}
As it loops through, I'll get all the schedules that fit the substring criteria showing on my calendar. That's great, but how can I test to assign the color of each schedule based on 'Type' as it loops through?
What I want to do is the following:
while (g.next()) {
If (type of schedule == 'blackout_dates')
{schedulePage.addSchedule(g.sys_id, #1f2624, null, true);}
else if (type of schedule == 'something else)
{schedulePage.addSchedule(g.sys_id, 'some other color' null, true);}
REPEAT AS NECESSARY...
}
Any help would be GREATLY appreciated!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 02:06 PM
This should work. Is it not working for you? Keep the color codes in quotes
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', 'CONTAINS', substring);
g.query();
while (g.next()) {
If (g.type == 'blackout_dates')
{schedulePage.addSchedule(g.sys_id, '#1f2624', null, true);}
else if (g.type == 'something else)
{schedulePage.addSchedule(g.sys_id, '#FF0000', null, true);}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 01:59 PM
Hi Rafael,
Just to be clear... does the following code that you share works for you ?
g.initialize();
g.addQuery('name', 'CONTAINS', substring);
g.query();
while (g.next()) {
schedulePage.addSchedule(g.sys_id, #1f2624, null, true);
}
Thanks,
Berny
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2017 06:50 AM
Hello Berny,
Yes, that code I posted works just fine. I'm just having a hard time understanding how to get the type of the schedule that is being pulled as the loop runs.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-09-2017 02:06 PM
This should work. Is it not working for you? Keep the color codes in quotes
var g = new GlideRecord('cmn_schedule');
g.addQuery('name', 'CONTAINS', substring);
g.query();
while (g.next()) {
If (g.type == 'blackout_dates')
{schedulePage.addSchedule(g.sys_id, '#1f2624', null, true);}
else if (g.type == 'something else)
{schedulePage.addSchedule(g.sys_id, '#FF0000', null, true);}
}
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-10-2017 06:53 AM
Hello Sanjiv,
I'll give this a try and see if this does indeed do something. I will totally feel like kicking myself if it's as simple as g.type haha. Sometimes the simplest answer is the one you need. I'll post an update if this works as intended!