Monday, August 29, 2022

A Mini Guide To Remote Tables – ServiceNow

 

A Mini Guide To Remote Tables – ServiceNow

Remote tables are another component that permits you to characterize a table inside ServiceNow. It also helps to interface it to an outer information source.

ServiceNow gets its records from running a related content against the outside information source.

These records live in memory, which implies they are clean after you leave the rundown/structure.

Before we go in detail with the remote tables. Let’s start with :

Why do we require remote tables?

Let’s try to see some usual challenges in data on Service-Now

  1. Complications to collaborate data distributed among various tables interrelated.

Usually we create a table, use Business Rules or scheduled jobs to maintain this data.

This approach has one big con which is small changes require modifications on multiple configurations such as data for an additional column.

  1. Handling of rarely utilized data from external sources.

Creating a table use schedule jobs to maintain these data and purge them on a regular basis or requirement. Con on this method is  inefficiency of data and API calls.

  1. Database views

They are use to combine two tables and have limitations such as advance conditions, access on records and much more.

Remote tables are the right solution for use cases mentioned above.

How do remote tables differ from regular tables?
  • Remote tables have a suffix “st” with their name using this we can differentiate a remote table and usual table.
  • Data for remote tables is cache and not store permanently. Using remote tables you are not utilizing your database storage rather data is cache in db to provide TTL.
  • Data can be generated when you are querying through scripts or viewing the table. No storage for data or handling of data for insertion and deletion.
  • Conditional based data generation.
  • Their details are store in Tables(sys_db_object) with Remote table check.
  • Values for Sys_id not generated by ServiceNow. It should generate logically.

Most important part is they support GlideRecord and ACLs like regular tables.

Requirements for using the tables?

Simply the below “plugin” is require and it comes to activate from Orlando.

Activate Plugin

How to create it?

Remote Tables —-> Tables. 

OOTB remote tables
  1. Click on “New”.
  2. Provide Label name is automatically set to populate.
  3. Save the record.

You might have observed that once you save the file. The record.Sys fields are missing??

For remote tables sys_id is the only sys field we have and it’s not auto populate.

Remote tables

  1. Create a definition.

Let’s try to have a look at the definitions.

Here is an example.
Remote Tables — > Definition.

In this definition it tries to pull interaction records with details such as portal source, language, device and application.

Here it just pulls data only when queries through a script which we “get” from a GlideRecord.

  1. Name: Name of your table/ details of the definition could be helpful.
  1. Table: Remote table name the definition applies to. One remote table can have only certain definition.
  1. Active: To stop/ run definition.
  1. Advanced: Advanced will provide a section to provide input for TTL.
  1. Script: Two parameters v_table & v_query.

Below is the sample definition create to show some data with a record that relates list of user groups and user.

v_table.addRow is use to create a record where object keys are field names and values are the values for records that will generate.

There is a catch here you cannot view this record as this data does not have any unique identifier. ServiceNow does not generate sys_id’s. You can provide unique identifiers (sys_id) of any value (not alphanumeric).

After modifying the definition with sys_id. You can even use sys_id of any existing data it should not lead to any database error as they are not store directly.

Working:

Remote tables require definitions to populate records. Definitions are scripts you can call an API or query tables to create JSON added as records.

How can we use remote tables?

v_query: API functions are as below:

 v_query.getEncodedQuery() – returns encoded query string example as below.

 v_query.getCondition(field) – returns encoded query string for the given field (includes field name, operator, and value)

 v_query.getParameter(field) – returns parameter for the given field (only includes value for equality conditions)

v_query.isGet() – returns whether the query is a single get by sys_id

v_query.getSysId() – returns parameter for sys_id field

 v_query.isTextSearch() – returns whether the query contains a text query parameter

 v_query.getTextSearch() – returns text search query parameter (internal field name 123TEXTQUERY321)

 v_query.getFirstRowWanted() – returns the first row to include

 v_query.getLastRowWanted() – returns the last row to include

For More Details And Blogs : Aelum Consulting Blogs
If you want to increase the quality and efficiency of your ServiceNow workflows, Try out our ServiceNow Microassesment.
For ServiceNow Implementations and ServiceNow Consulting Visit our website: https://aelumconsulting.com/servicenow/


Thursday, August 25, 2022

Table Hierarchy In ServiceNow: Complete Guide

 

Table Hierarchy In ServiceNow: Complete Guide

GlideTable Hierarchy is a ServiceNow Server scoped API which provides information about the Table hierarchy and relationships. We have TableUtils API which can be used to retrieve the hierarchy of tables in ServiceNow.

So How actually the Table Hierarchy API is useful?

TableUtils is limited to the global scope in ServiceNow and it cannot be accessed from scoped application. So there is either of ways to achieve this solution:

  1. Copy TableUtils inside the scoped application.
  2. writing logic for GlideRecord the “sys_db_object” table.

This solution implementation might take some additional effort for a developer. So here TableHierarchy API can be very useful to bring our efforts down and easy in implementation. To get the hierarchy of any table in scoped applications. The below methods will be useful.

Method Summary:

Method Summary

In this Blog, We will drive through a few methods of this API with reference to the CMDB table hierarchy. For that we can use this API as follows:

API Definition: getTableExtensions() returns an array containing the table names that extend the current table.

Note: Current table will not be part of the return object. If you want to include the current table in the return object use getAllExtensions() method.

To fetch all the child tables(hierarchy) for the cmdb_ci_computer  table. We can use this method as explained below in the example.

Table Hierarchy
Output:

Output

Output:

cmdb_ci_computer, cmdb_ci_hardware, cmdb_ci, cmdb, cmdb_ci_ucs_blade, cmdb_ci_server, cmdb_ci_osx_server, cmdb_ci_mainframe, cmdb_ci_datapower_server, cmdb_ci_lb, cmdb_ci_lb_bigip, cmdb_ci_lb_a10, cmdb_ci_lb_cisco_csm, cmdb_ci_lb_alteon, cmdb_ci_lb_f5_gtm, cmdb_ci_lb_cisco_gss, cmdb_ci_lb_isa, cmdb_ci_lb_cisco_css, cmdb_ci_lb_ace, cmdb_ci_lb_radware, cmdb_ci_lb_network, cmdb_ci_lb_netscaler, cmdb_ci_lb_f5_ltm, cmdb_ci_ibm_zos_server, cmdb_ci_virtualization_server, cmdb_ci_vcenter_server_obj, cmdb_ci_esx_server, cmdb_ci_hyper_v_server, cmdb_ci_storage_server, cmdb_ci_win_server, cmdb_ci_linux_server, cmdb_ci_storage_node_element, cmdb_ci_isam_server, cmdb_ci_mainframe_lpar, cmdb_ci_server_hardware, cmdb_ci_tape_server, cmdb_ci_net_app_server, cmdb_ci_chassis_server, cmdb_ci_netware_server, cmdb_ci_unix_server, cmdb_ci_aix_server, cmdb_ci_solaris_server, cmdb_ci_hpux_server, cmdb_ci_cim_server, cmdb_ci_storage_switch, cmdb_ci_mainframe_hardware, cmdb_ci_pc_hardware, cmdb_ci_ucs_rack_unit

API Definition: getRoot() returns the top-level class in the hierarchy.

For Global, a Similar method is getAbsoluteBase() which returns the base table name from which the table was extended.

Note: For any table under the cmdb_ci hierarchy, this method returns cmdb_ci and not CMDB, which is the actual base table.

Table Hierarchy

Output:

cmdb

API Definition: getBase() returns the parent class which current class is extending like task(return) for incident(argument).

Table Hierarchy

Output:

Cmdb_ci_hardware

For More Details And Blogs : Aelum Consulting Blogs
If you want to increase the quality and efficiency of your ServiceNow workflows, Try out our ServiceNow Microassesment.
For ServiceNow Implementations and ServiceNow Consulting Visit our website: https://aelumconsulting.com/servicenow/



Tuesday, August 23, 2022

Easy 8 Steps To Setup LDAP In Laravel Application

 

Easy 8 Steps To Setup LDAP In Laravel Application

Understanding LDAP in Laravel Application

LDAP (Lightweight Directory Access Protocol) is a directory services protocol that is used for interacting with directory services.

One of the examples of directory services is Active Directory (AD) which is Microsoft’s proprietary directory service used to manage and store information about the devices, users, objects within an organization’s network.

So, here we will understand how to do LDAP connectivity in laravel to authenticate users in the active directory.

Easy steps to setup LDAP in Laravel Application

Step 01: Install the third-party LDAP package adldap2 in your laravel application using the below command.

composer require adldap2/adldap2-laravel

Step 02: Publish the installed package using the below command.

PHP artisan vendor:publish –provider=”Adldap\Laravel\AdldapServiceProvider”

Step 03: Most importantly, uncomment the dll for LDAP from the php.ini file first otherwise it will throw an error.

Step 04: Configure the following settings in ldap.php inside your config folder.

Inside Settings:
‘hosts’ => explode(‘ ‘, env(‘LDAP_HOSTS’, ‘ldap.forumsys.com’)),
‘base_dn’ => env(‘LDAP_BASE_DN’, ‘dc=example,dc=com’),
‘username’ => env(‘LDAP_USERNAME’),
‘password’ => env(‘LDAP_PASSWORD’)

For an anonymous user, leave username and password it as it otherwise mentions the username and password.

Step 05: At step 4 the configuration has been done, now check the connection by running a query in the login controller to fetch user records from the active directory. curie is a test user for ‘ldap.forumsys.com’ directory.

$search = Adldap::search()->where(‘uid’, ‘=’, ‘curie’)->get(); //Here uid is DN

Step 06: For authentication use the below sample code inside login controller.

$username= $request->input(‘name’);
$password= $request->input(‘name’);
$user_format = env(‘ADLDAP_USER_FORMAT’, ‘uid=%s,’.’dc=example,dc=com’);
//change DN and base dn as per the requirement
$userdn = sprintf($user_format, $username);
Adldap::auth()->bind($userdn, $password);
if(Adldap::auth()->attempt($userdn, $password, $bindAsUser = true))
{
echo ‘Login successful’;
}
else
{
echo “Username or password invalid”;
}

Step 07: After having a successful test connection don’t forget to replace ‘ldap.forumsys.com’ with your actual directory address.

Step 08: Let’s run the application and try to log in.

For More Details And Blogs : Aelum Consulting Blogs
If you want to increase the quality and efficiency of your ServiceNow workflows, Try out our ServiceNow Microassesment.
For ServiceNow Implementations and ServiceNow Consulting Visit our website: https://aelumconsulting.com/servicenow/


Thursday, August 18, 2022

Case Study: Limiting The Number Of Joined Customers Using SQL Transaction Isolation Levels

 

Case Study: Limiting The Number Of Joined Customers Using SQL Transaction Isolation Levels

Agenda: In many real-time applications, at times we have to limit the total number of users to a limit. Ex: while booking movie tickets, or gaming events, and so on.  The problem at hand is to limit the total number of users registered in such scenarios. 

We will consider virtual cricket match application registration for the use case. 

Background of the Scenario

Following is a walkthrough of the actions in the picture:

  1. Users register themselves.
  2. Users see a list of different cricket matches that will start within an hour timeframe. The timer is running in the background.
  3. The User clicks on a cricket match from the list. Now the user has to create a virtual team of cricket players to play the match. 
  4. The User clicks on a cricket match from the list. Now the user has to create a virtual team of cricket players to play the match. 
  5. As soon as the team is created a list of contests appears. Users now have to join any contest. Some amount will be deducted from the wallet depending on the contest the user is joining.
  6. Now there is a limit of users who can join a particular contest.

For example, suppose there are only 2 spots for contest A. When the user clicks Join Contest and the number of slots is filled then he should not be able to join.

The task seems to be unchallenging and effortless. Simply apply an if..else.. condition which checks if the maximum limit is exceeding and terminates the transaction before insertion if it exceeds. 

But here comes the catch in this supposititious scenario. There are lakhs of users using the application at the same second. Say a couple of thousand users click on the Join Contest button at the same time. Hence instead of 2 users, 1000 users are able to join the match. Their money from the wallet is also deducted which becomes a huge challenge. This is a serious predicament and a massive technical issue.

學習筆記] SQL 大小事Isolation Level 與SARGs | Marsen's Blog

Solution: SQL Transaction Isolation Levels 

When multiple database transactions are occurring at the same time, transactions have to be isolated from each other so as to complete the transaction properly. The SQL standard defines four levels of isolation. 

 Now following database anomalies come into the picture:

  1. Dirty read: A transaction reads data written by a concurrent uncommitted transaction.
  2. Non-Repeatable reads: A transaction re-reads data it has previously read and finds that data has been modified by another transaction (that committed since the initial read).
  3. Phantom Reads: A transaction re-executes a query returning a set of rows that satisfy a search condition and finds that the set of rows satisfying the condition has changed due to another recently-committed transaction.
  4. Serialization anomalies: The result of successfully committing a group of transactions is inconsistent with all possible orderings of running those transactions one at a time.

To eliminate these anomalies, we use transaction isolation levels.

Choosing the best isolation level based, have a great impact on the database, each level of isolation comes with a trade-off, let’s discuss each of them:

1. Read Uncommitted

Read Uncommitted is the lowest isolation level. In this level, one transaction may read not yet committed changes made by another transaction, thereby allowing dirty reads. At this level, transactions are not isolated from each other.

Syntax: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

2. Read Committed

This isolation level guarantees that any data read is committed at the moment it is read. Thus it does not allow dirty reads. The transaction holds a read or write lock on the current row, and thus prevents other transactions from reading, updating, or deleting it.

Syntax: SET TRANSACTION ISOLATION LEVEL READ COMMITTED

3. Repeatable Reads

This is the most restrictive isolation level. The transaction holds read locks on all rows it references and writes locks on all rows it inserts, updates, or deletes. Since other transactions cannot read, update or delete these rows, consequently it avoids non-repeatable reads.

Syntax: SET TRANSACTION ISOLATION LEVEL READ REPEATABLE READS

4. Serializable

This is the highest isolation level. A serializable execution is guaranteed to be serializable. Serializable execution is defined to be an execution of operations in which concurrently executing transactions appears to be serially executing.

Syntax: SET TRANSACTION ISOLATION LEVEL READ SERIALIZABLE

The following table describes the various conditions and the applicability of transactions.

Use case: Virtual cricket match application registration
Table ‘[dbo][Players]’

NOTE: Following case shows the syntax of the SQL server. For other database platforms, syntax can be modified.

Consider a table ‘Players’ having the following structure:

syntax

Database concept: There are Database Hazards That interrupt or corrupt database transactions. Following are the database hazards:

  • 1. Dirty read
  • 2. Update loss 
  • 3. Phantom

These hazards are outbreaks that we tackle using Isolation Levels

SQL Transaction Isolation Levels to tackle the hazards. 
1. SQL Transaction Isolation level 1: READ UNCOMMITTED

Consider two users, Player 1 and Player 2. Following transactions are made by these users:

PLAYER 1 (Session 1)

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL READ UNCOMMITTED
INSERT INTO [dbo].[Players] ([Player_id],[Player_name],
[Contest_name], [Maximum_players],[Amount]) VALUES (10005,
‘Vaibhav’, ‘Hot Contests’,8, 1288)
-> WAIT FOR DELAY 20s
-> ROLLBACK TRANSACTION 

PLAYER 2 (Session 2)

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL READ UNCOMMITTED
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
\1 record returned
-> WAIT FOR DELAY 20s
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
\0 records returned (dirty read)
-> END TRANSACTION

RESULT

Player 1 inserts into the table and waits for the 20s. Meanwhile, Player 2 selects the record just inserted. Player 2 is able to see this uncommitted record. Now after 20s User 1 rollback transaction. When Player 2 selects again no record is fetched. This is a case of Dirty Read.

Hence READ UNCOMMITTED eliminates none of the anomalies and is the lowest stage of Isolation level.

DIRTY READ ———-Not removed
UPDATE LOSS——–Not removed
PHANTOM————–Not removed

2. SQL Transaction Isolation level 2: READ COMMITTED

Consider 2 players Player 1 and Player 2. Following transactions are made:

PLAYER 1 (Session 1)

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL READ COMMITTED
INSERT INTO [dbo].Players VALUES (10005, ‘Vaibhav’, ‘Hot Contests’,8,
‘Rs.1288’)
-> WAIT FOR DELAY 20s
-> ROLLBACK TRANSACTION

PLAYER 2 (Session 2) **Dirty read removed

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL READ COMMITTED
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
\No records are returned as it is not committed.
-> WAIT FOR DELAY 20s
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
\ No records returned as the transaction is rolled back.
-> END TRANSACTION

RESULT

Player 1 inserts into the table and waits for the 20s. Meanwhile, Player 2 selects the record just inserted. Player 2 is not able to see the record as it is uncommitted. Now after 20s Player 1 commits a transaction. When Player 2 selects again no record is fetched as it is rolled back.

Hence READ COMMITTED eliminates the first database hazard: DIRTY READS and is the second stage of Isolation level. 

DIRTY READ ———-Removed
UPDATE LOSS——–Not removed
PHANTOM————–Not removed

3. SQL Transaction Isolation level 3: REPEATABLE READ

Consider 2 Players: Player 1, Player 2. Following transactions are made by the users:

USER 1 (Session 1)

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL REPEATABLE READ
-> UPDATE [dbo].[Players] SET [Amount]=1,20,000 WHERE
[Emp_id]=10005
-> WAIT FOR DELAY 20s
-> COMMIT TRANSACTION
-> END TRANSACTION

USER 2 (Session 2) ** Update loss removed

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL REPEATABLE READ
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
//No records returned as there is a lock on this record.
-> WAIT FOR DELAY 20s
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10005
//One record is returned as the lock opens after the 20s.
-> END TRANSACTION

RESULT

Player 1 updates one record in the table but has not committed it yet and waits for the 20s. Meanwhile, Player 2 selects the record being updated by User 1. Player 2 is not able to see the record as it is uncommitted. Now after 20s Player 1 commits a transaction. When Player 2 selects the record again and the updated record is returned. Hence Player 2 is able to fetch the record only when the transaction is either ROLLBACK or COMMITTED. 

Hence REPEATABLE READ eliminates the second database hazard: UPDATE LOSS and is the third stage of Isolation level. 

DIRTY READ ———-Removed
UPDATE LOSS——–Removed
PHANTOM————–Not removed

4. SQL Transaction Isolation level 4: SERIALIZABLE

Consider 2 players Player 1, Player 2. Following transactions are made by the users:

USER 1 (Session 1)

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL SERIALIZABLE
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10006
\10 records are returned and the user makes a report of the number
of records for this Player_id.
-> WAIT FOR DELAY 20s
-> SELECT * FROM [dbo].[Players] WHERE Player_id = 10006
//Fetches 2 more records. Extra records fetched.
-> END TRANSACTION

USER 2 (Session 2) ** Phantom removed

-> GO
-> BEGIN TRANSACTION
-> SET ISOLATION LEVEL SERIALIZABLE
-> INSERT INTO [dbo].[Players] ([Player_id],[Player_name],
[Contest_name],[Maximum_players],[Amount]) VALUES (10005,
‘Vaibhav’, ‘Head to Head’,8, ‘Rs.774’)
\\1 record inserted
-> INSERT INTO [dbo].[Players] ([Player_id],[Player_name],
[Contest_name],[Maximum_players],[Amount]) VALUES (10005,
‘Vaibhav’, ‘Hot Contests,8, ‘Rs.414’)
\\1 record inserted
-> COMMIT TRANSACTION
-> END TRANSACTION

RESULT

Player 1 selects one record in the table with Player_id=10006. 10 records are returned and Player 1 prepares the report on it. Meanwhile, Player 2 is inserting 2 records in the table for Player_id=10006. After a 20-second delay Player 2 commits a transaction. Now player 1 again selects records for Player_id=10006 and 12 records are returned. A mismatch of data occurs and the report is not correct. This is a massive transactional error called Phantom and database reports also become incorrect.

To tackle this hazard, we use a SERIALIZABLE isolation level which applies a lock on records between a specific range of PLAYER_ID says 10005-10010. Now the Player cannot insert a record within this range before the transaction is committed by Player 1.

Hence SERIALIZABLE eliminates the third database hazard: Phantom and is the fourth stage of Isolation level. 

DIRTY READ ———-Removed
UPDATE LOSS——–Removed
PHANTOM————- Removed

Hence SERIALIZATION is the strongest lock as it eliminates all three database hazards.

Hence concluding, understanding the concept of Transactional Isolation Level is crucial to resolve SQL transaction-related glitches and maintaining database integrity and a lot of Database Hazards can be eliminated making the transactions go smoothly.

For More Details And Blogs : Aelum Consulting Blogs
If you want to increase the quality and efficiency of your ServiceNow workflows, Try out our ServiceNow Microassesment.
For ServiceNow Implementations and ServiceNow Consulting Visit our website: https://aelumconsulting.com/servicenow/