logo

NJP

ServiceNow introduction to GlideSchedule API for Date/time validation with demo

Import · Oct 31, 2022 · video

foreign [Music] we'll be looking how we can use schedule okay in order to do date and time validation so for an instant just consider an example okay that you have a use case that for change request okay if a change request has a plan started in certain time frame then it should get assigned to a a group and if it's outside that particular time frame then it should get assigned to B group okay now if you think from a wider perspective right this is not easily achievable using the library time API okay why because what you have to do on a daily basis it's a daily basis kind of thing okay on a daily basis you have to see uh a time frame if certain thing is falling inside that time frame then it will get assigned to e-group and if it's falling outside that time frame then it it will get assigned to B group okay now how we can achieve this it's buzzing your mind right okay so this kind of uh problems okay can be resolved when it's when it's related to time frame it can be resolved by using schedule so everyone must be knowing our schedule right so scared it is something where you define certain time frame okay and you'll use the schedule in order to execute schedule job SLS and and a lot of things okay so let's focus on that today so for today use case our use case will be like all change request there is a plan start date okay if a plan start date Falls between certain time frame okay then it should get assigned to one group if it falls outside that time frame then it should get assigned to other group okay so for this first of all don't use light daytime API okay in the start first of all you have to create a schedule so so we'll go and create a schedule so under system scheduler okay this is scheduled under schedule there is scheduled and we will give it a name or what we have to give um change schedule okay I will just copy this name out because I want to use this out for the time zone we will keep it floating or uh or I will keep it my local time zone so that I can explain you out okay parent I don't want to give okay this is for eign demo okay so I will save this out and now once the schedule get created we get this related list right so now we have to create a schedule entry for the same so we'll go new okay overeo also I will give the same schedule you can create multiple schedule and it will check for because we'll be doing the validation on the parent schedule only type I don't think we should give anything it's not mandatory also busy and let's see now we'll put a use case that nine to three okay let's take R so it will be from 9 am to 3 P.M right so 3 P.M will be 15. right 15. and let's make it applicable from yeah so from 23rd I'll make this as so 23rd yeah so it's from 9 00 am to 3 P.M okay if it falls into this it will get assigned to one group that's outside the group repeat interval you have to give daily okay and repeat until if you want to Define certain time till this till that time this schedule should work so you can give but we will keep it as is for now and I will give save okay the three times you have entries are not valid okay and let's let's keep it this only okay not a problem so we'll give nine to 15. yeah there will be just save why not rather I will just reload this form out to see okay and it will be zero nine let's give it this way and over here let's keep the date 24. because I think it's not in the future date okay and we will save it out now it got saved perfect I think I missed this out repeat we have to do daily okay once so save now we have created schedule okay so in schedule we have we have not done anything special okay or anything rocket science we have just defined the schedule in which particular time frame we have to form now we will go to the change so I will mark this as favorite for now and we'll go to the change record okay change request dot list you know changed to [Applause] okay and over here now what we have to do is like we will write a business rule right so I will do configure config a business rule so it should be based on the plan start date right the first and the foremost thing what I will be doing is I will change okay we will go for advanced condition when it should it should run before insert update okay what it should do so first and the foremost thing we need to address a variable and [Applause] start date will be equal to we have to Simply go over here so we here we will go for fields and the phase where is the plan started plastered plus started okay so this is how you can get this out okay so current dot start this shortcut just a tip okay then what we have to do is like variable schedule okay okay let's make it gr schedule let's follow our own breast practices and equal to equal to new slide new light record what I'm doing okay England record will give CNN underscore schedule why because it's a entry for the parent scheduled record then we will be doing Gia light schedule dot add query and inside ad query we will we will be going with the name so I will put name not paying name and the name will pass the name which we have given to the parent schedule which is change schedule and then it will be gr High schedule dot query okay I'm not really sure if you are able to see very then if they are scheduled next we know it has a record but if and it has if if it has multiple uh scalar entries also that's fine it will check through all of them okay and so what we have to do now we got that particular scheduled Glide record right okay so we will be doing variable variable schedule equal to new light schedule okay this is an API and this API we have to pass the CIS ID of the parent schedule okay so it will be yeah dot get unique value perfect till now okay now we got this thing and we also have the plus started but this plan starter will be in string format right we have to convert it into Glide date time format okay so how we can do that so we can do it via flight data so I will give variable price start date okay equal to new slide the time ending light date time we'll be passing this value which is okay now this is done flash started now we got the plan started now we have to check whether this particular plan started Falls inside the schedule or not okay so how we can check that so there is a method uh for the same so it's like if scheduled Dot there is a function called as in schedule okay and then schedule and it asks for one attribute which is the date okay last update if it's in schedule then we'll give some message okay now what we'll keep messages here dot add information I'll give it simply inside just to verify the things out let's head schedule and L will give the same we'll set it to the assignment group once we get confirm okay because I have not tried it out so I will give right schedule okay this is done okay so we will save it out now and we will shampoo here and we'll go to the quiz talk to okay and I will unpin that out and over here now if this is a change form if I give a schedule currently is 11 o'clock so it should be inside schedule only so if I save this out so it gave inside schedule so this criteria is working fine if I give it outside 3 pm after 3 pm right so I'll give 5 PM 5 will be oh 20 17 17 PM okay it's outside 3 P.M so it should give outset skill perfect it's working I expected now we will just get it assigned to the assignment group so we will have this okay so this assignment group underscore list okay I will just copy this out why because we want to find some groups okay so I have already created some group okay let's see if we can utilize this out okay so I'll go over here and we will dot two so I've created two groups for the same end time support and outside out time support so I will just copy this ID of this so if this message and we can do what we can do current dot set value for what assignment group and what should be the value for that if it's inside will give this and it fits outside okay then we will give the outside one as it's a before business rule so we don't have to give current dot update kind of thing okay just keep it in mind big big big big no for that okay so I just have to change the group this inside and now this is the outside one so I will update the Sid for this and then we can give it a try again perfect it got stored now I will reload the form as the reload form now let's I think it's outside now let's make it inside first okay so I will make it 29 see so assignment group is empty right now okay and if I save this out did I save it out if I save this out then it's inside schedule and it get assigned to end time support group perfect right now if I move it outside okay so I will make it some 19 okay it's outside schedule and if I save this out now so it should get assigned to out time support group okay if I sub save it the message is outside scheduled and it gots us it got set to outside out time support okay so from today's tutorial what we learned is likely the schedule is not the thing which we just used during data Imports and all that right okay you can use schedule to do daytime validation also specific time valuation we can see okay uh you can also use it for daytime validation for example you want certain things if if or certain records are getting created eight to five over the working days and all those kind of thing okay their schedule is very helpful okay you don't have to add a lot of logic for the same okay so we understand how the schedule Works how we can use it to do the date time validation we have looked into one use case where uh we have defined a time frame for change request plan started if it falls into that time frame then it will get assigned to one group if it falls outside that time frame then it will get assigned to another group okay if you have any queries on this particular tutorial uh you can drop me a mail on my email ID or you can reach out to me on my LinkedIn account I will try to get connected with you if you have still if you have any other queries okay so you can please drop a comments okay over this video okay I will I will try to look into the comments and I will try to get it resolved okay till then stay safe stay happy and have a nice day thank you

View original source

https://www.youtube.com/watch?v=RUE46QeWt2o