- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 07:08 AM
i have a button on the form and i would to know can i trigger a outbound call ?
i have the outbound rest message configured
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2024 11:25 PM
managed to get it working.
// Initial log to ensure script execution
gs.log('UI Action script started', 'DellSOAPRequest');
try {
// Get current user's information
var currentUser = gs.getUser();
var firstName = currentUser.getFirstName();
var lastName = currentUser.getLastName();
var emailAddress = currentUser.getEmail();
var mobilePhone = currentUser.getRecord().getValue('mobile_phone');
gs.log('Current User Info - FirstName: ' + firstName + ', LastName: ' + lastName + ', Email: ' + emailAddress + ', Mobile Phone: ' + mobilePhone, 'DellSOAPRequest');
// Initialize the RESTMessageV2 object to get the token
var tokenRequest = new sn_ws.RESTMessageV2();
tokenRequest.setEndpoint('https://apigtwb2cnp.us.dell.com/auth/oauth/v2/token');
tokenRequest.setHttpMethod('POST');
tokenRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// Set the request body with the necessary parameters
tokenRequest.setRequestBody('grant_type=client_credentials&client_id=&client_secret=');
var tokenResponse = tokenRequest.execute();
var tokenResponseBody = tokenResponse.getBody();
var tokenStatus = tokenResponse.getStatusCode();
gs.log('Token Response Status: ' + tokenStatus, 'DellSOAPRequest');
gs.log('Token Response Body: ' + tokenResponseBody, 'DellSOAPRequest');
if (tokenStatus != 200) {
throw new Error('Failed to obtain OAuth token: ' + tokenResponseBody);
}
var tokenData = JSON.parse(tokenResponseBody);
var token = tokenData.access_token;
gs.log('OAuth Token: ' + token, 'DellSOAPRequest');
// Initialize the RESTMessageV2 object for the main request
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('https://apigtwb2cnp.us.dell.com/Sandbox/support/case/v3/WebCase');
r.setHttpMethod('POST');
// Set the Authorization header with the Bearer token
r.setRequestHeader('Authorization', 'Bearer ' + token);
r.setRequestHeader('Content-Type', 'text/xml');
gs.log('HTTP headers set', 'DellSOAPRequest');
// Set request body with XML content
var xmlPayload = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ph.services.dell.com/Server/">' +
'<soapenv:Header />' +
'<soapenv:Body>' +
'<ser:AlertRequest>' +
'<SourceHeader>' +
'<ClientId></ClientId>' +
'<ClientType>HELPDESK</ClientType>' +
'<ClientHostName></ClientHostName>' +
'<ClientIPAddress>0.0.0.0</ClientIPAddress>' +
'<GuId></GuId>' +
'<ClientVersion></ClientVersion>' +
'<RequestId></RequestId>' +
'</SourceHeader>' +
'<CustomerHeader>' +
'<CompanyName>test</CompanyName>' +
'<CountryCodeISO></CountryCodeISO>' +
'<EmailOptIn></EmailOptIn>' +
'<PrimaryContact>' +
'<FirstName>' + firstName + '</FirstName>' +
'<LastName>' + lastName + '</LastName>' +
'<Country></Country>' +
'<TimeZone></TimeZone>' +
'<PhoneNumber1>' + mobilePhone + '</PhoneNumber1>' +
'<EmailAddress>' + emailAddress + '</EmailAddress>' +
'<PreferContactMethod>email</PreferContactMethod>' +
'<PreferContactTimeframe></PreferContactTimeframe>' +
'<PreferLanguage>en</PreferLanguage>' +
'</PrimaryContact>' +
'</CustomerHeader>' +
'<AlertData>' +
'<EventId>2</EventId>' +
'<TrapId>0</TrapId>' +
'<EventSource>Server</EventSource>' +
'<Severity>3</Severity>' +
'<Message></Message>' +
'<Timestamp>2024-05-03T13:30:00+0200</Timestamp>' +
'<ServiceTag></ServiceTag>' +
'<PartSerialNo></PartSerialNo>' +
'<FileToken></FileToken>' +
'<AgentSource></AgentSource>' +
'<DeviceName></DeviceName>' +
'<DeviceIP></DeviceIP>' +
'<DeviceModel></DeviceModel>' +
'<DeviceType></DeviceType>' +
'<OS></OS>' +
'<DiagnosticsOptIn></DiagnosticsOptIn>' +
'<CaseSeverity>Medium</CaseSeverity>' +
'<Code></Code>' +
'<RecommendationId></RecommendationId>' +
'</AlertData>' +
'<WebCaseOperation>' +
'<Operation>ALERTS</Operation>' +
'</WebCaseOperation>' +
'</ser:AlertRequest>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
gs.log('XML Payload: ' + xmlPayload, 'DellSOAPRequest');
r.setRequestBody(xmlPayload);
gs.log('Request body set', 'DellSOAPRequest');
// Execute the REST message
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Log the response for debugging
gs.log('Response Body: ' + responseBody, 'DellSOAPRequest');
gs.log('HTTP Status: ' + httpStatus, 'DellSOAPRequest');
if (httpStatus != 200) {
gs.log('Error: ' + response.getErrorMessage(), 'DellSOAPRequest');
} else {
// Parse response to get CaseId, CaseStatus, and Status
var caseIdMatch = responseBody.match(/<CaseId>(.*?)<\/CaseId>/);
var caseStatusMatch = responseBody.match(/<CaseStatus>(.*?)<\/CaseStatus>/);
var statusMatch = responseBody.match(/<Status>(.*?)<\/Status>/);
var caseId = caseIdMatch ? caseIdMatch[1] : 'N/A';
var caseStatus = caseStatusMatch ? caseStatusMatch[1] : 'N/A';
var status = statusMatch ? statusMatch[1] : 'N/A';
var workNotes = 'Case created with Case ID: ' + caseId + ', Case Status: ' + caseStatus + ', Status: ' + status + ' (ticket submitted successfully).';
gs.log('Work Notes: ' + workNotes, 'DellSOAPRequest');
// Add work notes to the current record
current.work_notes = workNotes;
current.update();
}
} catch(ex) {
// Handle any exceptions that occur during the execution
var message = ex.message;
gs.log('Error: ' + message, 'DellSOAPRequest');
// Optionally, add error message to work notes
current.work_notes = 'Error: ' + message;
current.update();
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 08:34 AM
Hi @chercm ,
The preview script usage gets all the info on the method including the variable substitution.
So this is correct, you need to send the authentication details to execute this method. Rest all looks fine.
Thanks,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-13-2024 03:48 PM
@Community Alums
@Community Alums
do you mean the following for the authentication ?
var r = new sn_ws.RESTMessageV2(); r.setEndpoint('https://apigtwb2cnp.us.dell.com/Sandbox/support/case/v3'); r.setHttpMethod('POST'); r.setRequestHeader('Content-Type', 'text/xml'); r.setRequestHeader('SOAPAction', 'http://ph.services.dell.com/Server/AlertOperation');
r.setAuthenticationProfile('oauth2', 'Dell default_profile');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 10:02 AM
Hi @chercm
Please refer below steps
1. In your outbound message HTTP method you have one related link called Preview Script Usage
2. Create UI Action which is not client callable, and add script which you retrive from step one.
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-12-2024 05:26 AM - edited 06-12-2024 05:26 AM
i came out with this script which will check on the field whether it is a dell machine before executing . is the correct logic ?
try {
var incidentSysId = current.sys_id;
var impactedAssetSysId = current.u_imapcted_asset;
if (impactedAssetSysId) {
var assetGR = new GlideRecord('alm_asset');
assetGR.get(impactedAssetSysId);
if (assetGR.isValidRecord() && assetGR.display_name.startsWith('Dell')) {
// Asset is a Dell, proceed to send the REST message
// Get the technician details
var technicianId = gs.getUserID();
var userGR = new GlideRecord('sys_user');
if (userGR.get(technicianId)) {
var firstName = userGR.first_name;
var lastName = userGR.last_name;
var emailAddress = userGR.email;
var companyName = userGR.company.name; // Assuming there's a company associated with the user
var timeZone = userGR.time_zone; // Get the technician's time zone
// Convert time zone to +0800 format
var tzOffset = new GlideDateTime().getTZOffset(timeZone);
var formattedTimeZone = tzOffset.slice(0, 3) + tzOffset.slice(4); // Convert to +0800 format
var r = new sn_ws.RESTMessageV2('Dell ticket', 'POST');
// Setting the parameters
r.setStringParameterNoEscape('LastName', lastName);
r.setStringParameterNoEscape('PreferContactMethod', 'email');
r.setStringParameterNoEscape('PreferLanguage', 'en');
r.setStringParameterNoEscape('ClientId', '730634');
r.setStringParameterNoEscape('ClientHostName', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('CountryCodeISO', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('Country', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('RequestId', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('Message', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('FirstName', firstName);
r.setStringParameterNoEscape('PhoneNumber1', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('GuId', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('ClientVersion', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('ClientIPAddress', '0.0.0.0');
r.setStringParameterNoEscape('EmailAddress', emailAddress); // Replace with actual data as needed
r.setStringParameterNoEscape('PreferContactTimeframe', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('CompanyName', companyName || 'Default Company'); // Ensure company name is set
r.setStringParameterNoEscape('TimeZone', formattedTimeZone); // Set the formatted time zone
r.setStringParameterNoEscape('EmailOptIn', ''); // Replace with actual data as needed
r.setStringParameterNoEscape('ClientType', 'HELPDESK');
// Override authentication profile
r.setAuthenticationProfile('oauth2', 'Dell default_profile');
// Execute the REST message
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Handle the response
if (httpStatus == 200) {
gs.addInfoMessage('Dell ticket sent successfully!');
// Extract CaseId from the response
var caseIdMatch = responseBody.match(/<CaseId>(.*?)<\/CaseId>/);
var caseId = caseIdMatch ? caseIdMatch[1] : 'Unknown CaseId';
// Update the work notes of the incident
var incidentGR = new GlideRecord('incident');
if (incidentGR.get(incidentSysId)) {
incidentGR.work_notes = 'Dell ticket created with CaseId: ' + caseId;
incidentGR.update();
}
} else {
gs.addErrorMessage('Failed to send Dell ticket. Status: ' + httpStatus + ' Response: ' + responseBody);
}
} else {
gs.addErrorMessage('Failed to retrieve technician details.');
}
} else {
gs.addErrorMessage('The selected asset is not a Dell.');
gs.addErrorMessage('The selected asset is not a Dell machine.');
// Alert Popup
var dialog = new GlideDialogWindow('alert_dialog');
dialog.setTitle('Asset Check');
dialog.setBody('<div style="padding: 20px;">The selected asset is not a Dell machine.</div>', false, false);
dialog.render();
}
} else {
gs.addErrorMessage('No impacted asset selected.');
}
} catch (ex) {
var message = ex.message;
gs.addErrorMessage('An error occurred: ' + message);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-16-2024 11:25 PM
managed to get it working.
// Initial log to ensure script execution
gs.log('UI Action script started', 'DellSOAPRequest');
try {
// Get current user's information
var currentUser = gs.getUser();
var firstName = currentUser.getFirstName();
var lastName = currentUser.getLastName();
var emailAddress = currentUser.getEmail();
var mobilePhone = currentUser.getRecord().getValue('mobile_phone');
gs.log('Current User Info - FirstName: ' + firstName + ', LastName: ' + lastName + ', Email: ' + emailAddress + ', Mobile Phone: ' + mobilePhone, 'DellSOAPRequest');
// Initialize the RESTMessageV2 object to get the token
var tokenRequest = new sn_ws.RESTMessageV2();
tokenRequest.setEndpoint('https://apigtwb2cnp.us.dell.com/auth/oauth/v2/token');
tokenRequest.setHttpMethod('POST');
tokenRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
// Set the request body with the necessary parameters
tokenRequest.setRequestBody('grant_type=client_credentials&client_id=&client_secret=');
var tokenResponse = tokenRequest.execute();
var tokenResponseBody = tokenResponse.getBody();
var tokenStatus = tokenResponse.getStatusCode();
gs.log('Token Response Status: ' + tokenStatus, 'DellSOAPRequest');
gs.log('Token Response Body: ' + tokenResponseBody, 'DellSOAPRequest');
if (tokenStatus != 200) {
throw new Error('Failed to obtain OAuth token: ' + tokenResponseBody);
}
var tokenData = JSON.parse(tokenResponseBody);
var token = tokenData.access_token;
gs.log('OAuth Token: ' + token, 'DellSOAPRequest');
// Initialize the RESTMessageV2 object for the main request
var r = new sn_ws.RESTMessageV2();
r.setEndpoint('https://apigtwb2cnp.us.dell.com/Sandbox/support/case/v3/WebCase');
r.setHttpMethod('POST');
// Set the Authorization header with the Bearer token
r.setRequestHeader('Authorization', 'Bearer ' + token);
r.setRequestHeader('Content-Type', 'text/xml');
gs.log('HTTP headers set', 'DellSOAPRequest');
// Set request body with XML content
var xmlPayload = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://ph.services.dell.com/Server/">' +
'<soapenv:Header />' +
'<soapenv:Body>' +
'<ser:AlertRequest>' +
'<SourceHeader>' +
'<ClientId></ClientId>' +
'<ClientType>HELPDESK</ClientType>' +
'<ClientHostName></ClientHostName>' +
'<ClientIPAddress>0.0.0.0</ClientIPAddress>' +
'<GuId></GuId>' +
'<ClientVersion></ClientVersion>' +
'<RequestId></RequestId>' +
'</SourceHeader>' +
'<CustomerHeader>' +
'<CompanyName>test</CompanyName>' +
'<CountryCodeISO></CountryCodeISO>' +
'<EmailOptIn></EmailOptIn>' +
'<PrimaryContact>' +
'<FirstName>' + firstName + '</FirstName>' +
'<LastName>' + lastName + '</LastName>' +
'<Country></Country>' +
'<TimeZone></TimeZone>' +
'<PhoneNumber1>' + mobilePhone + '</PhoneNumber1>' +
'<EmailAddress>' + emailAddress + '</EmailAddress>' +
'<PreferContactMethod>email</PreferContactMethod>' +
'<PreferContactTimeframe></PreferContactTimeframe>' +
'<PreferLanguage>en</PreferLanguage>' +
'</PrimaryContact>' +
'</CustomerHeader>' +
'<AlertData>' +
'<EventId>2</EventId>' +
'<TrapId>0</TrapId>' +
'<EventSource>Server</EventSource>' +
'<Severity>3</Severity>' +
'<Message></Message>' +
'<Timestamp>2024-05-03T13:30:00+0200</Timestamp>' +
'<ServiceTag></ServiceTag>' +
'<PartSerialNo></PartSerialNo>' +
'<FileToken></FileToken>' +
'<AgentSource></AgentSource>' +
'<DeviceName></DeviceName>' +
'<DeviceIP></DeviceIP>' +
'<DeviceModel></DeviceModel>' +
'<DeviceType></DeviceType>' +
'<OS></OS>' +
'<DiagnosticsOptIn></DiagnosticsOptIn>' +
'<CaseSeverity>Medium</CaseSeverity>' +
'<Code></Code>' +
'<RecommendationId></RecommendationId>' +
'</AlertData>' +
'<WebCaseOperation>' +
'<Operation>ALERTS</Operation>' +
'</WebCaseOperation>' +
'</ser:AlertRequest>' +
'</soapenv:Body>' +
'</soapenv:Envelope>';
gs.log('XML Payload: ' + xmlPayload, 'DellSOAPRequest');
r.setRequestBody(xmlPayload);
gs.log('Request body set', 'DellSOAPRequest');
// Execute the REST message
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Log the response for debugging
gs.log('Response Body: ' + responseBody, 'DellSOAPRequest');
gs.log('HTTP Status: ' + httpStatus, 'DellSOAPRequest');
if (httpStatus != 200) {
gs.log('Error: ' + response.getErrorMessage(), 'DellSOAPRequest');
} else {
// Parse response to get CaseId, CaseStatus, and Status
var caseIdMatch = responseBody.match(/<CaseId>(.*?)<\/CaseId>/);
var caseStatusMatch = responseBody.match(/<CaseStatus>(.*?)<\/CaseStatus>/);
var statusMatch = responseBody.match(/<Status>(.*?)<\/Status>/);
var caseId = caseIdMatch ? caseIdMatch[1] : 'N/A';
var caseStatus = caseStatusMatch ? caseStatusMatch[1] : 'N/A';
var status = statusMatch ? statusMatch[1] : 'N/A';
var workNotes = 'Case created with Case ID: ' + caseId + ', Case Status: ' + caseStatus + ', Status: ' + status + ' (ticket submitted successfully).';
gs.log('Work Notes: ' + workNotes, 'DellSOAPRequest');
// Add work notes to the current record
current.work_notes = workNotes;
current.update();
}
} catch(ex) {
// Handle any exceptions that occur during the execution
var message = ex.message;
gs.log('Error: ' + message, 'DellSOAPRequest');
// Optionally, add error message to work notes
current.work_notes = 'Error: ' + message;
current.update();
}