integrate Dell case management with servicenow
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2024 05:16 AM - edited 01-24-2024 05:25 AM
i want to have a button on the incident page to capture some details and send it via outbound api call to Dell to open support ticket but does not seems to be working
var DellTechDirectAPI = Class.create(); DellTechDirectAPI.prototype = { initialize: function() { }, createDellCase: function(incidentSysId, parameters) { // Retrieve parameters var apikey = parameters.apikey; var firstName = parameters.firstName; var lastName = parameters.lastName; var companyName = parameters.companyName; // Include other parameters similarly // Construct the request body var requestBody = { 'apikey': apikey, 'firstName': firstName, 'lastName': lastName, 'companyName': companyName, // Include other parameters similarly }; // Make the API call to Dell's case management API var response = this.makeDellCaseAPIRequest(requestBody); // Handle the response as needed var httpStatus = response.getStatusCode(); var responseBody = response.getBody(); if (httpStatus === 200) { // API call successful gs.info('Dell case created successfully. Response: ' + responseBody); } else { // API call failed gs.error('Failed to create Dell case. HTTP Status: ' + httpStatus + ', Response: ' + responseBody); } }, makeDellCaseAPIRequest: function(requestBody) { // Create RESTMessageV2 var restMessage = new sn_ws.RESTMessageV2('DellCaseManagementAPI', 'Post'); // Set the request body restMessage.setRequestBody(JSON.stringify(requestBody)); // Set additional headers if needed restMessage.setRequestHeader('Content-Type', 'application/json'); // Execute the REST message var response = restMessage.execute(); return response; }, type: 'DellTechDirectAPI' };
Show insert button
// UI Action: OpenDellCase // Table: incident // Show insert button (function executeUIAction(current, previous /*null when async*/) { var dialog = new GlideDialogWindow('dell_case_popup'); dialog.setTitle('Create Dell Case'); dialog.render(); })(current, previous);
UI page
Create Dell Case First Name: Submit function submitDellCase() { // Retrieve values from input fields var firstName = document.getElementById('firstName').value; // Retrieve other input values similarly // Call the function to create the Dell case with entered data createDellCase(firstName /*, other parameters */); } function createDellCase(firstName /*, other parameters */) { // Include the necessary logic here to set parameters and make the API call // You can use the DellTechDirectAPI Script Include // For example: var apikey = gs.getProperty('DellTechDirectKey'); var dellAPI = new DellTechDirectAPI(); dellAPI.createDellCase(current.sys_id, { 'apikey': apikey, 'firstName': firstName, // Include other parameters similarly }); }
3. Modify the DellTechDirectAPI Script Include:
Ensure that the DellTechDirectAPI Script Include includes the logic to create a Dell case using the provided parameters.
cript includes
var DellTechDirectAPI = Class.create();
DellTechDirectAPI.prototype = {
initialize: function() {
},
createDellCase: function(incidentSysId, parameters) {
// Retrieve parameters
var apikey = parameters.apikey;
var firstName = parameters.firstName;
// Include other parameters similarly
// Construct the request body
var requestBody = {
'apikey': apikey,
'firstName': firstName,
// Include other parameters similarly
};
// Make the API call to Dell's case management API
var response = this.makeDellCaseAPIRequest(requestBody);
// Handle the response as needed
var httpStatus = response.getStatusCode();
var responseBody = response.getBody();
if (httpStatus === 200) {
// API call successful
gs.info('Dell case created successfully. Response: ' + responseBody);
} else {
// API call failed
gs.error('Failed to create Dell case. HTTP Status: ' + httpStatus + ', Response: ' + responseBody);
}
},
makeDellCaseAPIRequest: function(requestBody) {
// Create RESTMessageV2
var restMessage = new sn_ws.RESTMessageV2('DellCaseManagementAPI', 'POST'); // Replace 'DellCaseManagementAPI' with the actual name of your RESTMessageV2
// Set the request body
restMessage.setRequestBody(JSON.stringify(requestBody));
// Set additional headers if needed
restMessage.setRequestHeader('Content-Type', 'application/json');
// Execute the REST message
var response = restMessage.execute();
return response;
},
type: 'DellTechDirectAPI'
};
Navigate to System Definition > Tables and create a new table named "Queue." Add fields like incident_sys_id, payload, and request_status as needed.
business rule
(function executeRule(current, previous /*null when async*/) {
if (current.u_request_status == 'pending') {
// Assuming that the 'payload' field contains the JSON payload with parameters
var payload = JSON.parse(current.payload);
// Call the function to create the Dell case with entered data
var dellAPI = new DellTechDirectAPI();
dellAPI.createDellCase(current.incident_sys_id, payload);
// Update the request_status to indicate processing is complete
current.u_request_status = 'processed';
}
})(current, previous);
UI page
Capture Information
Incident Sys ID:
Submit
function createQueueRecord() {
// Retrieve values from input fields
var incidentSysId = document.getElementById('incidentSysId').value;
// Retrieve other input values similarly
// Create a record in the 'Queue' table
var gr = new GlideRecord('u_queue_table_name'); // Replace 'u_queue_table_name' with the actual name of your 'Queue' table
gr.initialize();
gr.incident_sys_id = incidentSysId;
gr.payload = JSON.stringify({
// Include the payload parameters
'apikey': 'your_api_key',
'firstName': 'John Doe',
// Include other parameters similarly
});
gr.request_status = 'pending';
gr.insert();
}
UI action
// UI Action: ShowCaptureInfoPage
// Table: incident
// Show insert button
(function executeUIAction(current, previous /*null when async*/) {
var dialog = new GlideDialogWindow('capture_info_page');
dialog.setTitle('Capture Information');
dialog.render();