interview Flashcards
(238 cards)
What is the purpose of Isolate script checkbox in client script?
It manages whether DOM manipulation should be enabled/disabled for client script. If DOM manipulation code is not working then there is possibility that this checkbox is true which is forcing client script to run in strict mode.
Which all client script gets executed when we change field value via list?
Only on cell edit client script gets executed when we update field via list view. We might think on change or on submit client script should also execute as we are changing field and submitting record to database but these two client script executes on form only.
When we are supposed to use client script and when to use UI policy?
UI Policies are recommended to use when we want to make field mandatory,read only or hide/show fields.
Client script can be used to write quite complex scripting. e.g. Setting value on form based on some condition, getting server side data on client side etc.
Note: We can write script in UI policy also but we should be using Client script wherever possible when it comes to writing client side scripting. We are supposed to use UI policy script only when same is not possible via client script.
What is g_form object? provide 5 methods of g_form object with its usage?
The GlideForm client-side API provides methods for managing form and form fields including methods to:
- Retrieve a field value on a form
- Hide a field
- Make a field read-only
- Write a message on a form or a field
- Add fields to a choice list
- Remove fields from a choice list
Below are the common methods of g_form object :
g_form.setValue : sets value in specified field.
g_form.getValue : gets value from specified field.
g_form.addInfoMessage : Display info message on form.
g_form.showFieldMsg : display field message.
g_form.addOption : Add new option in choice field.
How to prevent form submission via client script?
We can use “return false” statement in on submit client script to prevent form submission.
How to execute client script for specific view? or What is ‘Global’ checkbox in Client Script?
By default ‘Global’ checkbox is checked while creating new client script. It means client script will execute for all views. When we uncheck it, new field ‘View’ will be visible, we can mention view name here to execute client script for specific view.
Which all objects we can access in client script?
We can access below objects in client script
1. g_form
2. g_scratchpad
3. g_user
4. g_menu
5. g_item
6. g_scratchpad
How to send more than one variable from server side script to client side while using GlideAjax?
return multiple XML nodes and attributes from the server.
But there is a better alternative: return data using JSON. Doing this way, the data sent from the server is better structured and the script is easier to maintain as it is more comprehensible for the developer. From the server, you would encode the data to a JSON formatted string. From the client, you would retrieve the JSON formatted string and decode it into a javascript object.
Below, the detailed steps in both server and client side scripts :
Server side
- Prepare the data you want to send to the client. Data can be contained in a simple object or an array.
- Instantiate a JSON object and encode the data to be sent.
- Return the data. The data sent to the client is in a JSON formatted string.
var myObj = {};
return JSON.stringify(myObj);
Client side
- Retrieve the data
- Decode the JSON formatted string into an object or array, which contains multiple values.
- Process the values regarding the business requirements.
var myObj = JSON.parse(answer);
step that needs to be done on script include side to use it for GlideAjax?
Create your script include, check client callable.
Create a new client script,
Call your script include with new GlideAjax(script include)
What is eval function in client script
The EVAL function is used to basically evaluate variables and do “stuff” to it. You’ll mainly use it to create if, then functions to transform certain fields in tables or any other variable you want to manipulate. Improper use of eval() opens up your code for injection attacks
what is the difference between getXML() and getXMLAnswer()?
getXMLAnswer is slightly easier to write :slightly_smiling_face: and getXML returns a whole XML Document while getXMLAnswer only returns an Answer which is far more efficient.
getXMLAnswer() saves you a line of code every time you use it. That is it. There shouldn’t be any noticeable difference in speed, though this method is probably guaranteed to be slightly slower as it runs at least one more line of code each time. So ease of use vs minuscule difference in speed.
with getXMLAnswer() uou no longer need this line of code.
var comments = response.responseXML.documentElement.getAttribute(“answer”);
What will happen if we use GlideRecord in client script?
It works fine. However, Client-side GlideRecord is massively inefficient, far too slow, and returns way too much unnecessary data.
what are the backend tables
For all the tables we have one table that is stored in database and the table name is “sys_db_object.LIST” The backend name of a table in ServiceNow is a unique identifier that is used to reference the table in the database. It is typically a short, alphanumeric string that begins with the prefix “sys_”. The backend name of a table can be found by viewing the table’s properties in the ServiceNow user interface.
When we will use client script and script include with glide Ajax.
Whenever you need data in client script which is not available on the form then you will need to get it from server database. And to do so we can use GlideAjax. OR if you need to perform any operation/validation which requires server side script then we need to use GlideAjax.
If you used GlideAjax method to get server side data then why used GlideAjax, why not getReference or Display BR?
g_scratchpad is sent once when a form is loaded (information is pushed from the server to the client), whereas GlideAjax is dynamically triggered when the client requests information from the server.
If you’re using getReference you will get ALL data for each record you “get” whether you need it or not.
How to update change state from “Scheduled” to “Implement” automatically when Planned start date is reached?
- Create a BR on Change Table.
a. State = Scheduled
Advanced: use glide time
- You can either use Flow Designer or Scheduled Job.
- Schedule it to execute daily.
- Glide into ‘Change’ table and check if planned start date = todays date and state=scheduled then update change state to ‘implement’
What is the difference between synchronous and asynchronous client scripts? When would you use each type?
There is not exact concept called Synchronous/Asynchronous client script.
However, if you use GlideAjax (which makes async call) in client script to get data then you can say it is Asynchronous client script. And client scripts that do not use GlideAjax, you could say those are synchronous.
How do you debug client scripts in ServiceNow? Can you explain the techniques or tools you would use?
e can debug Client script by keeping alerts
var cat = g_form.getValue(‘catgory’);
alert(cat);
The most approached way I have seen that developers follow is using alert() method or console.log() method. This approach is no doubt helpful but, what if you are not sure at which line of code you are having data processing issue? You may end up with multiple alert messages and unknowingly you may end up irritating other people who are working on the form, as those alerts will popup on their screen as well .
Debug mode of browser developer tools in client scripts
If we are making the field read only with client script , can ITIL user can edit from list view ?
Yes, they can. We generally make fields read only via onLoad/onChage client script and it works only for form view not for list view.
Can you call a business rule through a client script?
You cannot call BR from client script. However, you can write Display BR to store values in g_scratchpad object and access that object in client script.
Practically there is no any scenario where you would need this. If you want any server side data in client script then you can always use GlideAjax in client script.
A group have only one member and I want to send the approval to it’s dedicated member and if he does’t exists,then send aproval to manager’s manager
How should I achive this through flow designer or BR
This can be implemented easily via workflow where you can inlcude validation script to check if dedicated user exist in that group, if not, then send it to managers manger. Workflow allows us to write such quite complex logic while triggering approval. However, I am pretty sure it can be achieved via Flow Designer as well but it becomes quite difficult to implement such logic in flow designer. I would not recommend to BR for triggering approvals as it becomes difficult to track approval status to perform further operation.
what is difference between Client scripts and Catalog Client Scripts.
Catalog client scripts stored in catalog_script_client table and Client scripts stored in sys_script_client table.
In catalog client script we have the option to apply the client script to the catalog item view, RITM view , Task view and also Target record view But in Client script we does not have that options.
In Client script we can apply the script to a specific view by checking the Global checkbox But in catalog Client script there is no Global check box because Catalog client script applies on a specific catalog item or a variable set.
in catalog client script their is no cell edit type client script we have only 3 types i.e onload, on submitte, on change that is major diffrence in that
How we can achieve this scenario
If approval is triggered to requester’s manager and if he does not approve for 3 days then it should pass to manager’s manager
e can achieve the above task by using flow designer by using approval action in it and setting the Wait For Condition of 3 days for Manager to approve it and then in case of not approved it will be assigned to Manger’s Manager
hat is the difference between setDisplay and setVisible method. I said, setVisible maintains space even if field is hidden and with setDisplay, we won’t have space in between the hidden fields. But Interviewer asked me to explain it in more technical way,
We have equivalent concept in CSS, if we use visibility:hidden in CSS to hide fields, it causes their space to be retained. But, on the other hand, if we use display:none, it causes space to be removed. So, I believe this is what ServiceNow uses in backend. This answer could have impressed interviewer.