#4 IF STATEMENT AND BOOLEAN LOGIC WITH EXAMPLES | SERVCIENOW JAVASCRIPT TUTORIAL | PRACTICAL DEMO
Hello friends welcome back to my YouTube channel basico service now learning so this is a fourth video of servicenote JavaScript tutorial and in this video we are going to explore if statement and Boolean logic along with this we are also going to implement one of the use case to understand that how we can use if statement and Boolean logic in serbisenow instance earlier we are done with these five Concepts now in this video we are going to cover the sixth one what is if statement and how we can implement the same or how we can use the same while scripting or while doing coding so friends if statements are basically used to control the flow logic it is used to execute the code when the condition evaluates to true or false okay for example if the condition evaluates to true so whatever code is mentioned over here in curly basis will get execute if the condition doesn't matter then whatever code is mentioned over here in s curly basis will get execute there are several ways to display or use if we can use the if statement only if we want we can use if else or we can also use if else if else okay so I will be displaying you the same with the example okay first we will take understanding of if statement and Boolean logic later on we will be implementing a use case to understand that how we can implement the same in service no instance okay so let's move to submission instance to understand if statement so friends this is my service now development instance type background over here as I have said that we will be using this background script editor to understand the concepts so let's say we are learning or we are exploring if statement over here okay so I am only exploring if statement currently so for example I am saying the variable x equals to 20 and I am saying where y equals to 25 okay I am saying if X is greater than y then execute uh GS dot info if statement only okay and here I have also paste something info other than off if statement block okay so here I have declared two variable here I am doing a comparison where I am saying if x is greater than 20 means if this particular evaluates to true then execute this otherwise move forward this is basically a only if statement I am not using else over here just click on run see other than of if statement this basically gets executed because this evolutes to false so because of that it's not moved to this particular block right if I am saying that if x is smaller than y for example here right in the script see both executes because anyhow this is not in any of the blocks so this code needs to be executed right now this condition evaluates to true so whatever code is mentioned in this if block get executed so I believe you have ID of it right now let's see if else statement okay so I am saying if x is smaller than y here I have to put else okay so in else we are not giving any condition because this will execute along with this if the condition doesn't matter then only this will get execute okay GS dot info here I'm saying else statement or else code executed or here I am saying if code executed just for understanding or executed okay so if x is smaller than y let's change the value again I am saying if x is greater than y then this will get execute else this will get execute and this anyhow will be getting execute because this is not a part of if and else right run the script see RS code executed because the condition doesn't matter right so whatever is false will get execute here in this way the code enters to a else block if the if condition doesn't matter and else block is there then the code whatever mentioned in the else will get execute okay now the third one is if statement okay so here let's say let me improve this bit for understanding purpose as if statement so I am saying if x is greater than y then execute this else if and then I have to give the condition over here else if x equals to equals to y then execute this and if both the condition doesn't matter then else execute the another thing GS dot info okay let me also put a semicolon over here now so the condition says if x is greater than y then this code will execute if x is equals to Y then this code will get execute and if these both the condition doesn't matter then this code will get execute you can use n numbers of else if that depends on your requirement right let me remove this ok now we are only dealing with as if if right so let's execute the same so here it says else code get execute because X is not equals to Y even X is not greater than y right let me put it as 25 here let's send this script see else if code execute because this condition is basically getting satisfied right in this way we can use if if else or else if statements right now I believe you have a basic idea of it unless you also have that just brushing up your things right so now let's move to another concept that is Boolean logic okay so let's see what is Boolean logic so in JavaScript we use if statements and Boolean logic plays a very important role in most of the scenarios Boolean logic introduce and or and not in JavaScript which basically helps to apply multiple conditional logic in single if statement conditional block so let's see how we can implement the same or use the same while writing the code so let's move to servicenow personal development instance again here so let me change something over here I will make it as Boolean logic okay here we have X let's consider is that 15 just to make a bit more interactive here I am saying another that is where Z equals to let's say 30 okay so here earlier we were only giving a single or we are comparising only a single thing right now if I have to say if x is greater than y and X is greater than Z okay so in this way we have used this particular and which says this evidence to true and this evaluates to True when both evaluates to true then only this will get execute okay same as as it is I will be saying that if Y is greater than x and and Y is greater than Z okay then this code will get execute I can say this is the first block just for understanding if IRS the first block let's for understanding we can say the second block second block okay here we also have used a Boolean logic that is and operator basically and says whatever mentioned over here both needs to be true then only the code will get execute okay again I am just putting also if over here I am saying if uh ah Z is greater than y and I am using another operator that is r Y is greater than X okay then the code will get execute that is the third block so what R basically says that if this evaluates to true all this evil it's true true out of these two if any of the particular statements evolutes to true then the code will get execute we can use n number of like any logic depends on the requirement I am just giving a basic of it that how we are using a Boolean logic operators over here right so let's execute third block which says Z is greater than y it is simulates to 2 and Y is greater than 15. let's say I make it as 10 so that this statement will not comes to true then run this see after that only this is evaluating to true this is not ability to True again it is getting executing because this basically or says that this or this right the one is satisfying the condition then it is executing whatever that is mentioned in the block okay so let's change something over here let's say x is greater than y yes and X is greater than Z so let's say make it 5. okay now this condition is getting satisfied right let's see so when both the condition are satisfying see then this particular code is getting executed okay so in this way we can use a Boolean logic so let's see what is the use case we are going to implement in submission instance to understand it that how we can use the same there so the use case scenario is that when users select state as in progress or resolved in incident form and save or submit the incident then alert message should be displayed to user reflecting the current state of incident so let me give you a brief of it first it's a very basic scenario just for understanding perspective I thought that it is better to give a basic idea of service by instance also right so here let's say let's open the incident form incident click on create new so use case says when user change the state to in progress or resolve and then save or submit the form then the alert message needs to be displayed to him okay then alert message should be displayed to the user reflecting the current state so let's say if the current state is in progress you just save the form then the alert message saying that the current state of incident is in progress if the user change the state to resolve and click on save or submit then the current then the let message will be displaying their current state of incident is resolved so let's see how we can achieve it okay so for that we are doing a client-side scripting because we are dealing with the form values right so let's say type client script over here open client click on new and let's say demo of if and Boolean logic right as we are implementing the same in incident type instant over here incident table right then we have to UI type if you want to change you can the type is on submit because I am saying when user click on save or submit right then on submit automatically in the syntax editor some code gets populated right here we have to write the code so as I have said if users select in progress or resolve right in the requirement when you just select as in Progressive resolve it means if user select in progress or results so the code says if now we are using if a statement right if G underscore form dot get value this is basically to fetch the value of a particular field the underscore form is an object of a glad form class which basically we use in client-side scripting so G underscore value of what of a field which field this field is basically a State field see State field okay so here we can say sorry State field oh sorry state equals to equals to here we are using a logical operators right so here we can say the state value should be in progress so how we can get the value in progress uh uh go here click here you can go to configure choices show Choi list type instant over here see here the values has been given so the Gat value is in progress that is 2. so I will be saying if State equals to 2 R see this is basically a r is basically a Boolean logic right here I am saying G underscore form dot get value Again State equals to resolve resolve a value of resolved is 6. so here I am saying 6 then what I have to do if the condition evaluates to true then alert what alert the value will be of current state right so the current state of the incident is I have to display the value over here right so to display the value I have to fetch the value first right so I will be saying where current state equals to G underscore form dot get option okay then field name and the string value then the field name is State and the value is basically G underscore form dot get value of what field state I will be give you a brief of that first just let me complete it okay and here I will be putting this statement over here okay let me check if I have missed something so I think I have missed that text over here okay so I am done with the code now so what I am doing over here see I am using Apple statement where I am saying that get the value of state that is 2 is in progress right then or if the value of a state is resolve then execute this so if the value of a state is in progress or the value is resolved then execute this right so to execute the current state what I am doing I am just is using this particular syntax to get a display value of a particular State okay display value not the value okay so value if I will be fetching so it will be giving me a numerical value but I need a label name of it so for that I have written this code where I am saying get option State and here I am passing a value the current value of a particular State and the text of it I am displaying over here right so let's save the thing let's navigate to incident form or type incident open it in a new window fill some values let's say able tutor demo basico service now and learning here I am putting the status in progress and saving it let's say what happened see it is showing me the alert that current state of the incident is in progress it means our code is working even though if I am putting is in in resolve and filling some mandatory information just a second see here and save it let's say save or submit then it is also showing me the another message that is the current state of the incident is resolved so the thing which we have mentioned in the use case that the alert message will be displayed to user reflecting the current state of incident we have achieved the same and in this example we have used the if statement even though we have also used the Boolean logic so in this way the basic concepts are helpful while doing a scripting or coding in service now platform so I believe now you have a better idea of it right so friends I have already created the content in over my website I will be posting those URLs uh in the description of a YouTube video you can find that URLs from there and you can access the content what I what I have displayed in the slide I think that will be helpful for you okay so friends this is all for this video so if this video is helpful please do like this video and if you are new to this channel for more service now videos you can subscribe my YouTube channel thank you friends have a nice day take care bye bye
https://www.youtube.com/watch?v=GvbExRqQbcQ