- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-23-2024 09:27 AM
Hi Experts,
I am new to SRAPIs. I am trying to implement a user functionality where, the user can select any number of records from the list view of a table and download it in CSV format. I am trying to achieve this via making use of SRAPI. However, I am unsure on how do I pass the user selected records sys ids while making the API call. Can anyone please help me undersatnd this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 09:10 AM
While I have not tested the following script, you can try it-
function invokeGetAPI() {
var sysIds = g_list.getChecked(); // Get the selected sys_ids from the list view
var apiUrl = '/api/your_scripted_rest_api_endpoint?selectedSysIds=' + sysIds.join(','); // Construct the URL for the GET API endpoint
// Make the GET request to the Scripted REST API
var xhr = new XMLHttpRequest();
xhr.open('GET', apiUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error('Error:', xhr.statusText);
}
}
};
xhr.send();
}
Also, can you mark my SRAPI answer correct and helpful for the interest of community?
Regards,
Amit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-24-2024 09:10 AM
While I have not tested the following script, you can try it-
function invokeGetAPI() {
var sysIds = g_list.getChecked(); // Get the selected sys_ids from the list view
var apiUrl = '/api/your_scripted_rest_api_endpoint?selectedSysIds=' + sysIds.join(','); // Construct the URL for the GET API endpoint
// Make the GET request to the Scripted REST API
var xhr = new XMLHttpRequest();
xhr.open('GET', apiUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.onreadystatechange = function () {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseText);
} else {
console.error('Error:', xhr.statusText);
}
}
};
xhr.send();
}
Also, can you mark my SRAPI answer correct and helpful for the interest of community?
Regards,
Amit