logo

NJP

ServiceNow introduction to GlideForm API | ServiceNow Client scripts | ServiceNow JavaScripts - 3

Import · Dec 19, 2022 · video

[Music] hi all and welcome back so this particular tutorial is the continuation of the previous tutorial as a part of service now JavaScript challenge okay uh so today's tutorial will be combination of two days T3 and de4 and we were looking into the Glide form apis if you have not seen the previous video please go jump out to the previous videos and see what we have implemented in now so we will we will continue looking into those few other functions as a part of the Live Form APA okay so without any without wasting any time let's get started so as always we'll be using incident table for our reference okay and we'll create a new client script so I will go configure um new client script I will give it a name as light form light from so 43 not so okay and as we have seen in the first tutorial we have this all load client script and the second we have used on chain so in this we'll be using one submit just just like that so let's get started okay so let's get started with the first function so the first function is called get action name okay so what that particular what this particular function does okay it Returns the most recent action okay of the client script for example if you are clicking on the save button then it will give the name of the that particular view action if you are clicking on the update button that it will give the information that you have clicked on update button and so on okay so the Syntax for the same is pretty easy so what you have to do we will go with the alert only alertings and I will give the name as detection action okay and the Syntax for it like G underscore form which is a prefix for all the things Dot get actioning that's it okay let's end at semicolon okay two seven not one semicolon and save okay so we'll go back to the form and we will reload the form every time we are doing the changes on the client script please reload the form okay and now I click on update then it should give the update as a name okay so effective update then give get action if you're just update what is this this is the action name for the reaction you must be knowing every your action has an action name so this is a you action name for that action okay I'm done now moving on to the second function so what we'll be doing we will comment this out okay and we will just copy this out a lot alert because I'm too lazy and now the second function which we want to look into is like get Boolean value okay so what this particular function does value so I think it will be clear from the name uh it returns a Boolean value for a specified field now you will be thinking that what's Boolean field so you know the check box right okay it's a Boolean food so it returns it actually works for it but will it not work for Choice period reference field reference field string field definitely it will work for that also so how exactly it plays the role over there then whenever we are using this function okay it returns pause if the feed value is either false or undefined if you have not defined anything also it will return false otherwise it will return true okay so let's get into the function and the Syntax for it like get Boolean value and in this we have to pass a string name okay string name or what of the field name okay so I want to check if the caller ID call afraid is empty okay or not so we'll save this out and jump back I'll jump back okay I'll jump back to the incident okay and now we'll click on update then it should give true because we can see the color is filled okay if it's not filled then it will give false okay so if I give I'll click update then it gives to that place this particular field is filled isn't it amazing now let's move on to the next field okay the next function we can say the next function in our list is get value okay so what this particular function does it gives the value okay of the entity which you have passed in okay so get value gives uh the society of of whatever we have passed okay if we have passed a caller ID then it will give the this ID of that caller ID record okay so how to write it down again will comment this out and I will copy this out and we can go you get not Boolean value get value and we will give get value or I will remove this out we get value okay and we have passed it as call of ID that means it will pass the sysid for that caller ID field okay so I will save this out okay I will go over here to the incident and if I click update okay then it should give the sysid for the caller ID feed if I click ok the get file to give this this ID and this is ID will be for the caller David Miller so this particular function is also done now the next in our list is get label off so what this particular function does get level off so get label of function gives label for any field okay okay it written the plain text value of any label okay so I will just comment this out okay and we will copy this out and we will get level of okay and here we have to give the function as get label off so we'll be looking in the label of color field okay I will save this out and if we go back to the form okay and we are looking for caller ID label okay and if I click on update then it gave the label you can see right we pass the backend value and gives the front end label for that particular field which is column okay so this is how the get level of works the next in our list is get related List names so basically what this particular function actually is pretty clear with the name only so what this particular function give does it gives a list of okay a liftoff related list okay which we have okay okay you can see it as adding array of related list okay um as an output for that particular record so I'll just copy this out and I will just press this out okay and the name is get and left let's okay and the Syntax for the same is get related list names okay so what it will give it will give the list of all the related List names okay so I will just save this out and sorry I missed one thing it doesn't require any input parameter so I will just remove this out save and if I go back to the incident form okay and now we can see let's see the related so in related list we have task SLA effective CIS in practice Services right so you should give this one so if I update it out so you can see we got task SLA cmwcr Services okay we got the list of all the related lists which are the for this particular record next in our list is get Section names okay so I will comment this out pretty easy functions according and I'll just copy this out I'll expected and now get related get sections right and the Syntax for the same is is get section names and we will save this out if I go back to the incident record now let's see first what all sections we have so we have node selected list with resolution information right so if I click on update so we got nodes and resolution information this is a backend name for all those sections okay so this is also done the next function in our list is get table name okay so basically now this particular function is quite useful when you check this checkbox inherited and you have condition based on multiple tables right from for example you have read the net on task table but you have different validation or incident problem and all those things then you can use this table to verify which particular table is this okay is this record belongs to and then you can add the validation on top of it so for this particular what this particular function does provides the table name of the record so I will give it an indicate people and it will not be a names it will be name because it will be returning only one entity and the syntax is pretty simple for that it's like get table name I'll save this out it got saved let's go back to the incident and if I submit if I update the record then it should give me incident as a table name because this record belongs to Instagram table see if I click on update okay the table name is incident perfect this is what we would expect so this is done the next in our list is and get unique value so what this particular function does it provides the unique value what is the unique value for any record that's this ID so it provides the Society of the current record okay so we'll give it your next ID and the Syntax for it is good index value no arguments are required I'll save this out and if we go back to the form okay and if I update then it should give this this ID for the incident record so if I click on update see it give the Swiss ID for this record for this incident record perfect pillow right now we will be discussing about the most we can say important and the most controversial method of all which is get reference okay so there are a lot of things around the same people think that it's not the best practice to use get reference and I've created a entire separate video on the same okay but it's not like that it's not a best practice you can get use get reference but what just it puts your code on Buffer right till you get the call so whenever you are using get reference do use it with uh a callback function uh so that it will it will it will it will not cause any problems right so let's look into that so how exactly the gate reference so first of all we will try to understand how exactly the gate reference function works okay so get reference function Returns the client record for the specified field okay so it works only for the uh reference field okay and you can write a call back to do the processing on top of that particular output or particular glad record okay so for example I want to check if the current user okay is a VIP user or not okay so how I can and this particular tag is on the corner table on the user table and I want to just dot walk to that particular user record and get the information so how we can do that for that we what we have to do we have to we are description form Dot get reference now we transport two things one is the field name as you can see on the screen and for which particular field name we want to do the Callback and the second will be the Callback function okay where we will be doing all the processing with respect to that particular field so it's color underscore ID because we want to look into the caller ID function so let's give it a name as do alert because we would be doing the alerting over there right and now once the get reference happens so for this particular field it will go to the user table grab the Glide record for this particular entry for example David Miller in our current case it will get the flight record for that then that particular record will be passed to this do alert method okay and we can process based on the information of that record in that particular function so how you can Define the Callback so just give do alert and then you can define a function over here function [Music] into third okay it will have one input which would be now this caller will be a Glide record of that color of the user object right so you can do all the all the things so you can do alert I'm doing this okay this and this color oh VIP okay and we asking question and the answer will be getting because we have the entire object right we can go caller nurse caller Dot and get the value of VIP so VIP is the field of the user table so we are just checking whether it's true or false okay so I hope this will be clear to everyone and you can do all kind of processing I'm just giving you a dumb example for the same okay okay so I will save it out we'll go back to the incident okay and if I click update then it it gave is the color VIP it's not that's why it's written false okay so this is today we have seen around 10 to 12 methods on the Glide form API okay hope this particular tutorial was helpful to you and if you have not seen the previous videos also in this series please do and check the same I'm having a lot of learning with this a scripting challenge okay and I'll continue creating videos on the same till then stay safe tap we keep learning and have a nice day ahead thank you

View original source

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