...
Once the content is crawl, we need to configure a ServiceNow REST API endpoint to retrieve all the criteria that is available to a specific user. This will be use during query time in Elastic Search, for the login userservice would be used when a logged in user is searching indexed content, using the email or the sys_id of the user, the list of available user criteria will filter the indexed content on Elastic Search.
To create a new specific Role for the new service, write “Role” on the Filter Navigator to the left and select the “Users and Groups -> Roles” option. Then click on the “New” button.
...
Write a name for the Resource (“getById” is recommended). Make sure that “HTTP method” is set to “GET” and the relative path reflects the specified name.
The script could use the user's email:
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var queryParams = request.queryParams;
var userEmail = queryParams.userEmail;
// Obtain the user system Id corresponding to the user Id
var userId = gs.getUser().getUserByEmail(userEmail).getName();
var adminUser = gs.getSession().getUserName().toString();
var impersonateSuccess = gs.getSession().impersonate(userId);
if (impersonateSuccess){
// Retrieve all user criteria
var allCriterias = SNC.UserCriteriaLoader.getAllUserCriteria();
response.setBody(allCriterias);
}
gs.getSession().impersonate(adminUser);
response.setContentType('application/json');
response.setStatus(200);
})(request, response);
Or the user's sys_id
(function process(/*RESTAPIRequest*/ request, /*RESTAPIResponse*/ response) {
// implement resource here
var queryParams = request.queryParams;
var userId = queryParams.userId;
var adminUser = gs.getSession().getUserName().toString();
var impersonateSuccess = gs.getSession().impersonate(userId);
if (impersonateSuccess){
// Retrieve all user criteria for the impersonated user
var allCriterias = SNC.UserCriteriaLoader.getAllUserCriteria();
response.setBody(allCriterias);
}
gs.getSession().impersonate(adminUser);
response.setContentType('application/json');
response.setStatus(200);
})(request, response);
Paste the provided code below the “// Implement resource here” comment and click submit.
...