Put a warning message on record producer

dfry123
Mega Expert

Is there a way to put a warning message on a record producer (Either when first going to the form or after submitting) that only shows up after a certain time?

I need to put a warning up that shows up only during the hours of 5 PM - 8 AM.

Thank You!

1 ACCEPTED SOLUTION

rob_pastore
ServiceNow Employee
ServiceNow Employee

oops, i think i screwed you up earlier.  



looking at the error it says that it doesn't recognize the function isInSchedule('string') - becasue that function requires a date object not a string.   i told you getNow would be an object and that's where i messed you up.



put this back in



var schedTime = new GlideDateTime(gs.nowDateTime());      


View solution in original post

28 REPLIES 28

Yes, the full script is below. This is on the record producer script.






gs.include("FormInfoHeader");
var fi = new FormInfoHeader();




var schedRec = new GlideRecord('cmn_schedule');              
schedRec.get('name','Workday 9:00 - 5:00');      
 
var sched = new GlideSchedule(schedRec.sys_id);              
 
var schedTime = new GlideDateTime(gs.nowDateTime());                      
 
gs.log('Time 1: ' + schedTime);
 
if (sched.isInSchedule(schedTime, 'US/Eastern')) {  
 
gs.addInfoMessage("in hours ");
}  
else {  
gs.addInfoMessage("after hours");


}  


rob_pastore
ServiceNow Employee
ServiceNow Employee

gs.getNowDateTime() should return an object, so you wouldn't need to do the new GlideDateTime with it.



try var schedTime = gs.nowDateTime();



and see what happens.


dfry123
Mega Expert

I really appreciate all your help. I am now getting a different error message in the logs:




find_real_file.png


rob_pastore
ServiceNow Employee
ServiceNow Employee

I think isinschedule() only takes one parameter - remove 'US/Eastern' and re test


dfry123
Mega Expert

I took that out and have the same error :



find_real_file.png