Angular WebApp to replace ServicePortal in ServiceNow
GPL-3.0 License
Angular 10+ web application developed to replace Service Portal on ServiceNow. It offers several benefits when compared native Service Portal
plugins
from application menus and select it. It will show all the applicationscom.snc.platform.security.oauth
and you should see OAuth 2.0 plugin and click on Install
oauth
in application menus and select Application Registries
and Click on New
button to create new OAuth clientsnc_platform_rest_api_access
and admin
roles. If not refer to ServiceNow user guide and add role to the user.$ curl -d "grant_type=password&client_id=<Client Id>&client_secret=<Client secret>&username=<UserId>&password=<Password>" -H "Content-Type: application/x-www-form-urlencoded" https://devxxxxx.service-now.com/oauth_token.do
grant_type=password
client_id=<Client Id>
client_secret=<Client secret>
username=<Username>
password=<Password>
{
"access_token": "z5Ewzj6KRSWXBnljlYRpn-R_5gw3JSQ8y1h71cuCIyVy546I7jwg5k9M2E0ctc2ssJC9S2ER6ZWGXs474Ext4Q",
"refresh_token": "Hek_vW3Q3jA2qM5nurYFCEruWPI5EX6zriI8a92v4FafFOsD5el17fWkrz48ZLlw3kpjZSRJmiK9uTyjPL6rKg",
"scope": "useraccount",
"token_type": "Bearer",
"expires_in": 1799
}
Now create the Scriped Rest API to return user roles when Angular app requests it
Go to ServiceNow instance and search for Scripted Rest APIs in applications and select it. Crete new Scripted Rest API by clicking on New button then entering Name:GetUserDetailsAPI and other details then submit it
Select created Scripted Rest API and create new Resource under resources and enter following info
HTTP method: GET
Name: GetUserDetails
Script:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response)
{
var userSysId=gs.getUserID();
var gr=new GlideRecord('sys_user_has_role');
gr.addQuery('user',userSysId);
gr.query();
var roles=[];
while(gr.next())
{
roles.push({name:gr.role.name,sysID:gr.role,description:gr.role.description});
}
var body=[];
body.push({username:gs.getUserName(),displayName:gs.getUserDisplayName(),sysId:gs.getUserID(),roles:roles});
response.setBody(body);
})(request, response);
This scripted api will be used in Angular App to access user information and roles. Mkae note of Base API path that looks like /api/19668/angulartest
, this will be used in next steps
export const SERVER_API_URL = 'https://dev81909.service-now.com/';
export const USER_INFO_URL = 'api/x_19668_halo/user_info';
export const OAUTH2_CLIENT_ID= '3c76622bc581b30082098914f97ee08e';
export const OAUTH2_CLIENT_SECRET= 'password12345';
export const OAUTH2_ACCESS_TOKEN_URI = SERVER_API_URL + 'oauth_token.do';
export const INCIDENT_API_URL = 'api/now/table/x_19668_halo_incident';
$ ng serve --watch