Edit color of schedule page item by 'Type'

raffy2
Kilo Contributor

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!

1 ACCEPTED SOLUTION

SanjivMeher
Mega Patron

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.

View solution in original post

5 REPLIES 5

bernyalvarado
Mega Sage

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


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.


SanjivMeher
Mega Patron

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.

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!