ServiceNow
Workflows

IT Workflows
Employee Workflows
Customer Workflows
Creator Workflows

IT Workflows
We offer workflows that can transform IT into a fully-fledged growth engine. Take advantage of the benefits of operational flexibility by increasing workforce adaptability...
Read More

Employee Workflows
Make employee experiences more integrated and engaging with ServiceNow Employee Workflows. Motivate your staff by making it simple for them to obtain what they require when they require it...
Read More

Customer Workflows
We connect clients, front-line agents, middle and back-office staff on a single ServiceNow platform with ServiceNow Customer Workflows using digital processes to scale customer operations...
Read More

Creator Workflows
With a low-code platform, you can quickly create digital workflow apps. Scale quickly across the organization to build natural, linked experiences that users enjoy...
Read More

Solutions
ServiceNow Solutions

IT Service Management
IT Operations Management
IT Asset Management
Governance, Risk, and Compliance
Security Operations

HR Service Delivery
Customer Service Management
Field Service Management
Integration Hub

IT Service Management
IT service management includes all the ServiceNow services and processes that ensure end to end...
Read More

IT Operations Management
ServiceNow ITOM consists of a set of modules in ServiceNow to manage the operations...
Read More

IT Asset Management
It is the set of business practices to manage the lifecycle of various assets in IT like software assets...
Read More

Governance, Risk, and Compliance
Almost every aspect of the business is driven by governance, risk, and compliance...
Read More

Security Operation
To minimize risk, ServiceNow SecOps allows you to immediately identify, prioritize, and respond to threats...
Read More

HR Service Deliver
With ServiceNow HRSD, you can increase company productivity and provide your employees...
Read More

Customer Service Management
Proactively solve problems and take actions to rectify common requests more efficiently with ServiceNow...
Read More

Field Service Management
ServiceNow Field Service Management enables you to efficiently and safely manage field service activity...
Read More

Integration Hub
For the fastest time to value, lowest TCO, and ease of use with zero learning curve for all ServiceNow developers...
Read More

Digital Transformation
Digital Transformation

DevOps
Robotic process automation
User Experience Design

DevOps
Devops includes the set of practices that automates the IT operations and accelerate the delivery...
Read More

Robotic process automationt
We help organizations to integrate different techniques like machine learning and artificial...
Read More

User Experience Design
User experience design is the creation of the effective flow between users and software...
Read More

Product Engineering
Product Engineering

IT Consulting
New Application development
Product testing & QA
Re-engineering & Migration
Support & maintenance

IT Consulting
We help Companies to Better their IT infrastructure and to Implement various IT strategies. Alignment of all the services to boost the overall performance...
Read More

New Application development
We are an IT service provider company using high-value business processes and technical stacks to build digital products...
Read More

Product testing & QA
We help clients to deliver quality products and services. Skilled Quality Assurance Team to perform a series...
Read More

Re-engineering & Migration
Re-Engineering and Migration is the concept of Comparing the Existing business model to the desired model...
Read More

Support & maintenance
We provide a range of support and maintenance services to our clients in the form of version upgrades, post-project support...
Read More

,

Introducing GraphQL To Your Regular ServiceNow Platform

  • By Aelum consulting
  • November 16, 2020
  • 724 Views

 

 

GraphQL API Framework is a new feature added as a part of  Now Platform Paris release.

 

It is a query language and runtime for Application Programming Interfaces (APIs) that prioritizes giving clients exactly the data they request and no more. GraphQL is designed to make APIs fast, flexible, and developer-friendly. It can even be deployed within an Integrated Development Environment (IDE) known as GraphQL.

 

 

What is GraphQL?

 

It is a query language for APIs and a runtime for fulfilling those queries with your existing data.

GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

 

 

Advantages of GraphQL

 

  1. You only need to call one endpoint with POST for everything you need. All parameters are in the request body.
  2. Query the exact data you need from a component.
  3. Discover fields and objects available to query through introspection.
  4. Manage multiple possible queries from a single API, as opposed to multiple endpoints for a REST request.
  5. Integrate with third-party systems by making the schema public.
  6. Generate the GraphQL query from your component and handle the response.

 

GraphQL + Postman

 

How to get data from ServiceNow using GraphQL (via Postman)

Let’s consider our requirement is to get the details of an incident record along with the details of the problem record related to that incident, based on its number.

 

 

Step 1 – Create a GraphQL Schema(GraphQL API) in ServiceNow:

 

  1. Navigate to System Web Services → GraphQL → GraphQL APIs and click New .
  2. Give a name to the Schema
  3. Give a Unique Schema namespace with in the application

 

 

 

We will require the schema namespace and application namespace at the time of querying the data

 

  1. Then finally build the Schema for the api

 

schema {
query: Query
}

type Query {
getIncidentByNumber(id:ID!):Incident
}

type Incident {
sys_id:String  @source(value: “sys_id.value”)
state:Values
caller_id:String
priority:Values
problem_id:Probs
}
type Values{
display_value:String
value:String
}
type Probs{
number: String @source(value: “number.value”)
state:String
short_description:String @source(value: “short_description.value”)

}

 

 

  1. Submit the record.

Using the above schema we are gonna query the Incident record as well the Problem record which is related to the incident.

 

 

Step 2 – Create a Scripted Resolvers for the schema :

 

  1. A  resolver script defines what value the schema returns when a component queries a specific field.
  2. If you don’t define a resolver for a field, the query returns any matching field value from the parent object type
  3. As per our schema we need to create 2 scripted Resolvers as we are gonna query 2 different tables(Incident & Problem ). In the newly created record scroll down to find the Scripted Resolvers Related List

 

 

 

For incident create a Resolver as follows  :

Name: Incident Resolver 

 

(function process(/*ResolverEnvironment*/ env) {
var incidentGr = new GlideRecord(‘incident’);
if (env.getArguments().id != null)
incidentGr.addQuery(‘number’, env.getArguments().id);
incidentGr.query();
return incidentGr;

})(env);

 

 

For problem create a Resolver as follows  :

Name: Problem Resolver 

 

(function process(/*ResolverEnvironment*/ env) {
var probId=env.getSource().problem_id.value;
var problemGr=new GlideRecord(‘problem’);
problemGr.get(probId);
return problemGr;
})(env);

 

 

Step 3 – Create Resolver Mappings for the schema :

Find the Resolver Mapping related list in the schema record and Map the resolvers to fields in the schema. This mapping lets the system know what value to return when a component queries a specific field.

 

 

 

schema

Now everything is set from the Servicenow Side. We have successfully created the GraphQL API to find the specific incident and its details

 

 

Step 4 – Build the query in the Postman app to get the incident details :

In Postman use the following configuration

End Point  : https://<instance>.service-now.com/api/now/graphql

Method : POST

Request Body Type : GraphQL

 

 

 

In The Request body Query Section add the following data:

 

 

Now Execute the query

 

 

You will get the response as follows :

 

 

 

Stay tuned!

 

Thoughts?

 

We would love to hear your team’s best practices and learnings in GraphQL.
This is a topic that is important to build long-lived GraphQL APIs.

 

 

1 thought on “Introducing GraphQL To Your Regular ServiceNow Platform”