Interview Questions
Can you create a record producer for the custom table which is not extended from the task Table? If yes, how can you do this?
What is Script Action?
Server-side JavaScript code that is executed when an event is triggered on the specified table.
Server-side debugging methods?
Debug Log displays gs.debug(), gs.info(), gs.print() and gs.log() statements as well as server logging information. However, gs.print() and gs.log() are not available in scoped applications, whereas gs.debug(), gs.info(), gs.warn(), gs.error() work in both scoped applications and global and are often used instead.
Can we override the Label name from the dictionary override?
No, we just have the different names created from Labels related list.
Can we have UI actions on View Specific?
No, we cannot.
Can we have a List View based on view specific ?
Yes, we can have. All columns can be defined from view configuration page.
Rest Table API's:
1. GET: GET /now/table/{tableName}
Retrieves multiple records for the specified table.
2. POST: POST /now/table/{tableName}
Inserts one record in the specified table. Multiple record insertion is not supported by this method.
3. PUT: PUT /now/table/{tableName}/{sys_id}
Updates the specified record with the request body.
4. PATCH: PATCH /now/table/{tableName}/{sys_id}
Updates the specified record with the name-value pairs included in the request body.
5. DELETE: DELETE /now/table/{tableName}/{sys_id}
Deletes the specified record from the specified table.
Client side debugging methods?
To debug processes on the client side, click the settings icon in the banner frame, select Developer from the menu and turn on JavaScript Log and Field Watcher. This will open the log viewer at the bottom of the window. Along with useful system information, you may choose to include jslog() statements in client scripts and UI policy scripts to help isolate and resolve issues.
Transform Event Scripts(Transform Map)
onStart: executes at the start of an import before any rows are read
onAfter: executes at the end of a row transformation and after the source row has been transformed into the target row and saved
onBefore: executes at the start of a row transformation and before the row is transformed into the target row
onChoiceCreate: executes at the start of a choice value creation before the new choice value is created
onComplete: executes at the end of an import after all rows are read and transformed
onForeignInsert: executes at the start of the creation of a related, referenced record before the record is created
onReject: executes during foreign record or choice creation if the foreign record or choice is rejected; The entire transformation row is not saved
Client Scripting Technical Best Practices
https://developer.servicenow.com/dev.do#!/guides/utah/now-platform/tpb-guide/client_scripting_technical_best_practices
Use Client Scripts to Validate Data
Set Client Script Order
Restrict List Editing
Enclose Code in Functions
Avoid DOM Manipulation
Minimize Server Lookups
The top ways to get information from the server are g_scratchpad, and asynchronous GlideAjax lookup.
Business Rules Technical Best Practices
Prevent Recursive Business Rules - Do not use current.update() in a Business Rule script.
Use Conditions in Business Rules
Keep Code in Functions
Know When to Run Business Rules
How to use client-side scripting in UI Actions?
To change a UI action to run client-side script, we first need to check the client field tick box.
https://docs.servicenow.com/en-US/bundle/sandiego-api-reference/page/script/useful-scripts/reference/using-client-server-code-ui-action.html
Difference between Synchronous and asynchronous in Servicenow?Difference between Synchronous and asynchronous in ServiceNow?
Synchronous means when ever you make a request to fetch values from server in your client script, code will wait there until it doesn't get a response from server. In Synchronous GlideAjax we use getXMLWait () function where user cannot move to other fields until the response is received from server. Synchronous getReference() method calls lock the form until the requested record is returned from the database.
Async mean regardless of request next line of code gets executed. It does not wait for response.
Asynchronous GlideAjax we use getXML () call back function where user can move to other fields as response from server process is going on backend.
Can we call the client script from the business rule?
You cannot call business rules through client script. You can only get the scratchpad value through display business rule. If you want to call server side script through client side you need to write script include and then call it through GlideAjax.
A display business rule sends this information to the client using the following script:
g_scratchpad.css = gs.getProperty('css.base.color');
g_scratchpad.hasAttachments = current.hasAttachments();
g_scratchpad.managerName = current.caller_id.manager.getDisplayValue();
To access scratchpad data using a client script:
// Check if the form has attachments
if (g_scratchpad.hasAttachments)
// do something interesting here
else
alert('You need to attach a form signed by ' + g_scratchpad.managerName);
There is a field on a form you applied client script to make that field invisible then apply UI policy to make it visible? What will be the output?
If you have applied client script onload then 1st it will hide the field and UI policy will make this field visible.
*** UI Policies execute after Client Scripts. If there is conflicting logic between a Client Script and a UI Policy, the UI Policy logic applies.******
In Service Portal, there is one field named quantity having values: [1, 2, 3, 4, 5]. Based on the quantity, the color will change and this should be done only using one class?
I want to populate only users in the caller field whose department is HR, and I don't want to user reference qualifier, how will you achieve this?
I want to send a link using notification to the knowledge article, on click of that link, we have to open that article?
On the change form, there are 2 fields with planned start date and end date, and we also created 2 custom fields with scheduled start date and end date, what will you do so that the custom field's duration should not exceed the planned start date and end date field values.
Display recent 5 records with priority is low(1) from Incident Table
var arr=[];
var inc=new GlideRecord('incident');
inc.addQuery('priority', '1');
inc.orderByDesc('sys_created_on');
inc.setLimit(5);
inc.query();
while(inc.next())
{
arr.push(inc.short_descriotion.toString());
}
gs.print(arr);
}
What is meant by Coalesce in ServiceNow?
The field property that is used in transform map field mapping is known as Coalesce. Coalescing on a field allows you to use that field as a unique key. The existing record will get updated with the imported information if a match with the coalesce field is found. If you can’t find a match, then insertion of a new record into the database will take place.
Explain record matching and data lookup features in ServiceNow.
The data lookup and record matching features allow you for setting up the field value based on a particular condition instead of scriptwriting. For example, on incident forms, the priority lookup rules automatically sample data. Now, set the priority of an incident based on the urgency values and the incident impact. Data lookup rules allow you to specify the fields and conditions where you wish data lookup to happen
What is a data policy?
Data policies are helpful to enforce data consistency by setting read-only and mandatory states. They can be quite relatable to UI policies, but the difference is UI policies are applied only to the data provided on forms using standard browsers. Also, it can apply rules to each data entered, like data entered through import sets, web services, email, or mobile UI. For example, if a mandatory field in the entered record is empty then it is possible to prevent the insertion of that record into the table by using data policy
What is HTML sanitizer in ServiceNow?
The HTML Sanitizer is useful in cleaning up HTML markup in HTML fields automatically. Also, it will eliminate unwanted code and protect against security threats like cross-site script attacks. Starting from the Eureka release, the HTML sanitizer is active for all instances
What is an inactivity monitor?
An inactivity monitor is used in event triggering for a task record if the task was kept in an inactive state for a certain period. If the task remains in an inactive state, the inactivity monitor repeats at regular intervals
Differentiate between next() and _next() method in ServiceNow.
The next() method is used for moving into the next record in GlideRecord. _next() is quite similar to next(), the difference is it is used when you query the table that has next as a column name
Actual elapsed time and Business elapsed time in SLA
Actual elapsed values are calculated on a 24x7 basis. Business elapsed values are calculated based on the schedule specified in the task SLA.
What is the purpose of the setWorkflow(e) function?
The setWorkflow(e) is useful in enabling or disabling the execution of business rules that are subsequent actions triggered. If you set the parameter “e” value to false, an insert/update operation will not be audited. When the parameter “e” value is set to true for a GlideRecord operation, then only auditing will be done. Parameter “e” represents a boolean variable that will enable business rules if the value is true(default), and will disable them if the value is false
By default duration field on task is empty and not calculated when task is closed. If want to update that field with actual duration I'll do below;
That way I updated all tasks but didn't fire any business rule.
var gr = new GlideRecord("task");
gr.addEncodedQuery('active=false^calendar_durationISEMPTY');
gr.autoSysFields(false); // so that the records don't have system updates
gr.query();
while(gr.next()) {
var gdt1 = new GlideDateTime(gr.sys_created_on.getDisplayValue());
var gdt2 = new GlideDateTime(gr.closed_at.getDisplayValue());
var dur = gs.calDateDiff(gdt1, gdt2, false);
gr.calendar_duration = dur;
gr.setWorkflow(false);
gr.update();
}
By default, for all the business rules it will be "setWorkFlow(true)", when we use the false, no field changes or. work notes will be seen under Activity logs.
Order of execution of an ACL:
The sequence is ROLES first, then condition, then script. Roles are cached so it's always more efficient to use roles whenever possible.
There are two ways to generate events:
Server-side script using the gs.eventQueue() method
Workflow Create Event activity
gs.eventQueue() Method
The eventQueue() method is part of the GlideSystem server-side API. The eventQueue() method inserts an event in an event queue. The eventQueue() method is typically passed four parameters but can also take an optional 5th parameter:
Event name. Enclose the event name in quotes.
GlideRecord object, typically current but can be any GlideRecord object from the event's table.
Any value that resolves to a string. This is known as parm1 (Parameter 1). Can be a string, variable that resolves to a string, or method that resolves to a string.
Any value that resolves to a string. This is known as parm2 (Parameter 2). Can be a string, variable that resolves to a string, or method that resolves to a string.
(Optional) Name of the queue to manage the event.
example:
gs.eventQueue('event.name', GlideRecord, parm1, parm2); // standard form
gs.eventQueue('x_58872_needit.overdueNeedItTask',current,current.number,gs.getUserName());
Comments
Post a Comment