- 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-09-2024 07:34 AM
Hi @chercm ,
At the form for your http method you have a related link called "Preview Script Usage". It will give you a script example on how to use the http method in a script. Add the script to your UI Action and modify as needed.
Regards,
Niklas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 07:37 AM - edited 06-09-2024 07:37 AM
Use Preview Script Usage to get script snippet that you can use. But you will need also process the response...
You can find in REST message definition in Related links

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-09-2024 08:00 AM
Hi @chercm ,
There are two ways to test this out.
1. Create a UI action and use the script from preview script usage.
2. Create a flow and use the Integration Hub Rest API call action
Code snippet for UI action-
// Define the UI Action script
(function() {
try {
// Initialize the REST message
var restMessage = new sn_ws.RESTMessageV2('Dell ticket', 'post');
// Set the request body with incident details
var requestBody = {
short_description: current.short_description,
description: current.description,
// Add other fields as required
};
// Set the request body for the REST message
restMessage.setRequestBody(JSON.stringify(requestBody));
// Execute the REST message and get the response
var response = restMessage.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
// Log the status and response for debugging
gs.addInfoMessage('REST API call status: ' + httpStatus);
gs.addInfoMessage('Response body: ' + responseBody);
} catch (ex) {
var message = ex.getMessage();
gs.addErrorMessage('Error occurred during REST API call: ' + message);
}
})();
If my response has resolved your query, please consider giving it a thumbs up and marking it as the correct answer!
Thanks & Regards,
Sanjay Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-10-2024 07:27 AM - edited 06-10-2024 07:30 AM
@Community Alums
@Community Alums
this is what i copy from preview :
try {
var r = new sn_ws.RESTMessageV2('Dell ticket', 'POST');
r.setStringParameterNoEscape('LastName', 'test');
r.setStringParameterNoEscape('PreferContactMethod', 'phone');
r.setStringParameterNoEscape('PreferLanguage', 'en');
r.setStringParameterNoEscape('ClientId', '730634');
r.setStringParameterNoEscape('ClientHostName', '');
r.setStringParameterNoEscape('CountryCodeISO', '');
r.setStringParameterNoEscape('Country', 'Singapore');
r.setStringParameterNoEscape('RequestId', '');
r.setStringParameterNoEscape('Message', 'Laptop burning');
r.setStringParameterNoEscape('FirstName', 'David');
r.setStringParameterNoEscape('PhoneNumber1', '+6599999999');
r.setStringParameterNoEscape('GuId', '');
r.setStringParameterNoEscape('ClientVersion', '');
r.setStringParameterNoEscape('ClientIPAddress', '0.0.0.0');
r.setStringParameterNoEscape('EmailAddress', 'abc@abc.com');
r.setStringParameterNoEscape('PreferContactTimeframe', '8-5pm');
r.setStringParameterNoEscape('CompanyName', 'ABC');
r.setStringParameterNoEscape('TimeZone', 'GMT+0800');
r.setStringParameterNoEscape('EmailOptIn', '');
r.setStringParameterNoEscape('ClientType', 'HELPDESK');
//override authentication profile
//authentication type ='basic'/ 'oauth2'
//r.setAuthenticationProfile(authentication type, profile name);
//set a MID server name if one wants to run the message on MID
//r.setMIDServer('MY_MID_SERVER');
//if the message is configured to communicate through ECC queue, either
//by setting a MID server or calling executeAsync, one needs to set skip_sensor
//to true. Otherwise, one may get an intermittent error that the response body is null
//r.setEccParameter('skip_sensor', true);
var response = r.execute();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
}
catch(ex) {
var message = ex.message;
}
i have used some variable to test but the preview script have those answer filled.