ServiceNow Usecase Field Visibility Based on Button | ServiceNow UI action Demo
[Music] thank you hi all and welcome back so in today's tutorial we will be looking on one of the use case which I faced recently in my project so basically the use case is like that we have a requirement where we want to hide and show a form field based on some view action so basically in simple words there will be a UI action on the form okay and if a person clicks on that form the clicks on that button then only that particular you field should be visible as and on that button click only it should hide also okay so you have to just toggle the field based on the your actions click so the best way to do is uh we can first we have to check the visibility of the field on the form if it's visible and a person clicks on the form on the button then it should get hidden and vice versa so in today's tutorial we'll be seeing what is the best way to achieve the same so as always we'll be doing this kind of experience on our favorite table which is incident table see and for today's use case what we'll be doing will create a UI action okay and what that your action will do pay on the click of that you actually will toggle the description field okay so let's get started so I'll simply go over your configure I will go to your actions I'll click on new and I will give it a name toggle description of this I will give it toggle description and then I will keep the table as incident only I'll make it on client okay and I will give one I will give a function name on toggle okay and copy this out and I will make it as a form button also let's make it as primary button I think that's it okay and let's get start coding it out so it will be a client set button okay we don't want to perform any activities on server so let's write function on toggle so it will be function on toggle I'll just zoom out little bit one target is let's first get let's first check whether that particular button is visible or not with that particular description field is physical or not okay so how we can verify that so I will be doing if G and this go to form Dot you must have not heard this this syntax okay so don't get after it so we will check is is visible and in that we'll be passing two attributes so the two attribute which particular which particular element we are looking for and to get the control for that element on the form so you can simply do that it has two attributes you can consider so it has to attribute like G and this could form dot get element slide element okay UIL your guide element and then you can pass the name of the frame so it will be description file [Applause] description and the second attribute will be G underscore form dot get control and control of which field so we'll again give the description over here so this will written whether the field is visible or not okay in a Boolean format so now if it's visible if it comes out to be true then what we have to do we have to just hide it out so we can forget G and descript form that this play of which field again description [Applause] to false because y first because the post statement written that the field is visible on the form and if it's not so we'll be writing an else for that else we will make it visible equal to true okay so basically I will go through the script okay so basically what we are doing we have created a u action which is a form you action is a primary form style okay and it will be our client side we are going on clip as a function on toggle and we have defined the function first we are checking if it's visible okay so for that we have passed to argument First Light Element description and get control for the description field okay if it's to if it's visible on the form then we are hiding it out if it's not visible in the else then we are just showing it off that's it so we will just save this out and let's go to the incident form so in the incident form now we can see a field called toggle description and we have a description field over here right let's remove the technical name so we have that description so if I click on this button this field should get disappeared why because it's currently visible on the phone and vice versa so let's so let's click on this button if you click this out so as you can see the description field got disappear and if I re-click on the C so the description field will get pop up so this is how you can control the visibility of any Fields or the form okay hope you like this video and find it useful in your project also okay if till then if you have any queries on the same please drop a comment on this video okay till then stay safe stay happy and have a nice day thank you
https://www.youtube.com/watch?v=zRL-mzGXbDQ