Copy value in field to clipboard in list view button

Sharath807
Tera Contributor

Hi all is it possible to copy the value in field from list view to clipboard . For example , if i have field in incident form called u_content . now if i create custom ui action in list banner and select records and click that button it should copy in clipboard.How can i achieve this . I tried below script in ui action its not working as expected.

copyContentToClipboard() {
    var gr = g_list.getChecked(); // gets selected rows in the list

    if (!gr || gr.length == 0) {
        alert('Please select a record.');
        return;
    }

    if (gr.length > 1) {
        alert('Please select only one record to copy.');
        return;
    }

    var sysId = gr[0];

    // Get the record data via GlideAjax or REST
    var ga = new GlideAjax('CopyFieldValueHelper');
    ga.addParam('sysparm_name', 'getFieldValue');
    ga.addParam('sysparm_sys_id', sysId);
    ga.getXMLAnswer(function(response) {
        var content = response || '';
        if (content) {
            copyToClipboard(content);
            alert('Copied: ' + content);
        } else {
            alert('Field is empty or not found.');
        }
    });
}
3 REPLIES 3

GlideFather
Tera Patron

Hi @Sharath807 

 

you can use:

  • ctrl+c (Win)
  • cmd+c (Mac)
  • right mouse button and copy 

Why would you create a button for it? 😛 is it for business process or part of learning?

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


@Sharath807 eventually use SNUtils if your browser is enabled for extensions:

SNUtils - Copy Selected Cell Values from List

———
/* If my response wasn’t a total disaster ↙️ drop a Kudos or Accept as Solution ↘️ Cheers! */


Sharath807
Tera Contributor

@GlideFather  Hi thanks for the reply. My requirement is to when click ui action in LIST banner  it should copy the content from HTML field type in LIST view from the selected record.