List View Download button

Raghav Manchand
Tera Contributor

I want to create List view UI action where the user can download a specific Excel File.

I'm trying to create a function but it seems to be not working or giving any response when the button is clicked.

The same ui action if I've not checked on client and without a function is working but I have to select a record which I don't want.

1 ACCEPTED SOLUTION

@Raghav Manchand 

Then use below script in UI Action.

onClick = confirmDownload()

 

function confirmDownload() {
	
	var URL = '<Link_Of_Attachment>';
    var down = confirm('Do you want to download the file?');
    alert(down);
    if (down) {
		g_navigation.openPopup(URL);
    }
}

 

View solution in original post

7 REPLIES 7

Mike_R
Kilo Patron
Kilo Patron

Can you post your code and a screenshot of your UI action settings?

RaghavManchand_0-1666858223806.png

Hi Mike,

There you go

 

Muhammad Khan
Mega Sage
Mega Sage

If you navigate to System UI > UI Context Menus, and search for Excel in Name column, open any record as per your need, there you will find script which might work for you. See the below image for reference.

MuhammadKhan_0-1666863549861.png

 

So, your UI Action Script would be like below.

Client: Checked

onClick: confirmExport()

 

function confirmExport() {
    var down = confirm('Do you want to download the file?');
    alert(down);
    if (down) {
        var exportHandler = new ContextMenuExportHandler(g_list, 'unload_excel_xlsx');
        exportHandler.exportRecords();
    }
}

 

 

First it will be exported, then you will have a button to either download or cancel. One more thing, instead of using download as a function name, try with some other name.

 

Hi @Muhammad Khan 

Thanks for the response but I wanted to download a particular file which I have uploaded to servicenow and I do have the file link for that. With your code it's exporting the records of the table.