- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2024 07:03 PM - edited ‎08-12-2024 07:06 PM
Hi,
I have developed the POST REST API integration of ServiceNow and Gitlab, where every time the particular case is created from the catalog it is creating a .JSON file in Gitlab with the Field values.
Current all values are coming in single as below.
{"Sysid":"7406275383bfc610994458a6feaad3ac","Case_no":"CS0001633","Action":"start","Multiple_Servers_Information":[{"Host_name":"PS LinuxApp01","Target_environment":"AWS","OS_type":"Linux Server","Process_name":"HTTPD"},{"Host_name":"PS LinuxApp02","Target_environment":"AWS","OS_type":"Linux Server","Process_name":"HTTPD"}]}
As per JSON format values should come below format.
{
"Sysid":"7f5ded8f833f4610994458a6feaad3f0",
"Action":"stop",
"Multiple_Servers_Information": [
{
"Host_name" : " PS LinuxApp01",
"Target_Environment": "AWS",
"OS_Type":" Linux Server ",
"Process_Name":"MariaDB"
},
{
"Host_name":" PS LinuxApp02",
"Target_Environment":"AWS",
"OS_Type":" Linux Server ",
"Process_Name":"PostFix"
}
]
}
Code:
var caseData;
var content = caseData;
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('POST');
request.setRequestHeader('content-type', 'application/json');
request.setRequestHeader('accept', 'application/json');
var requestBody = {
branch: 'main',
commit_message: 'Creating a file for Case(' + current.getValue("number") + ')',
content: JSON.stringify(content),
};
request.setRequestBody(JSON.stringify(requestBody));
var response = request.execute();
var responseBody = response.getBody();
Note: All the Authentication and endpoint details are removed from the code because of security constraints.
Appreciate your inputs will be help for to fix this issue.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2024 08:18 PM - edited ‎08-12-2024 08:21 PM
Hi @Omkar Jori Try with the highlighted Changes
var caseData = {
"Sysid": current.getValue("sys_id"),
"Action": current.getValue("u_action"),
"Multiple_Servers_Information": multiple_output
};
var content = JSON.stringify(caseData, null, 3);
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('POST');
request.setRequestHeader('content-type', 'application/json');
request.setRequestHeader('accept', 'application/json');
var requestBody = {
branch: 'main',
commit_message: 'Creating a file for Case(' + current.getValue("number") + ')',
content: content
request.setRequestBody(JSON.stringify(requestBody));
try {
var response = request.execute();
var responseBody = response.getBody();
gs.info('Response: ' + responseBody);
} catch (ex) {
gs.error('Error occurred: ' + ex.getMessage());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2024 07:07 PM - edited ‎08-12-2024 07:14 PM
Data stored in the Case form:
Catalog script to store the the Multi Row Variable set data to a field:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2024 08:18 PM - edited ‎08-12-2024 08:21 PM
Hi @Omkar Jori Try with the highlighted Changes
var caseData = {
"Sysid": current.getValue("sys_id"),
"Action": current.getValue("u_action"),
"Multiple_Servers_Information": multiple_output
};
var content = JSON.stringify(caseData, null, 3);
var request = new sn_ws.RESTMessageV2();
request.setHttpMethod('POST');
request.setRequestHeader('content-type', 'application/json');
request.setRequestHeader('accept', 'application/json');
var requestBody = {
branch: 'main',
commit_message: 'Creating a file for Case(' + current.getValue("number") + ')',
content: content
request.setRequestBody(JSON.stringify(requestBody));
try {
var response = request.execute();
var responseBody = response.getBody();
gs.info('Response: ' + responseBody);
} catch (ex) {
gs.error('Error occurred: ' + ex.getMessage());
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2024 08:24 PM - edited ‎08-12-2024 08:38 PM
Thank you @SK Chand Basha , It worked like a magic!!