Extract data in CSV file for selected records via Scripted REST API

Shalaka Vaze
Tera Contributor

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?

1 ACCEPTED SOLUTION

Hi @Shalaka Vaze 

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

View solution in original post

5 REPLIES 5

Hi @Shalaka Vaze 

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