How to create button to download incident record in CSV format (Using GlideDialogue window)

Imatiaz
Kilo Contributor

1. create a download button that should appear on the incident form to download the record in CSV format

1 ACCEPTED SOLUTION

@Lara Lynn 

This should help you

UI Action:

function downloadFile(){

	var sysId = g_form.getUniqueValue();
	var tableName = g_form.getTableName();
	var gDialog = new GlideDialogWindow('download_csv');
	gDialog.setSize('600','600');
	gDialog.setPreference('sysparm_sysID', sysId);
	gDialog.setPreference('sysparm_tableName', tableName);
	gDialog.setTitle('Download Incident');
	gDialog.render();
}

UI Page:

HTML:

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

	<g:ui_form>
		<input type="hidden" name="recordSysId" id="recordSysId" value="${sysparm_sysID}"/>
		<input type="hidden" name="tableName" id="tableName" value="${sysparm_tableName}"/><input type="button" onclick="downloadCSV()" name="Download" value="Download"></input>
		<input type="button" onclick="onCancel()" name="Cancel" value="Cancel"></input>
	</g:ui_form>

</j:jelly>

Client Script:

function downloadCSV(){

	var tableName = gel('tableName').value;
	var recordSysId = gel('recordSysId').value;
	top.window.open('/' + tableName + '.do?CSV&sys_id='+recordSysId); // Is working fine
	GlideDialogWindow.get().destroy();
}

function onCancel() {
	GlideDialogWindow.get().destroy();
	return false;
}

Output:

find_real_file.png

Once they click "Download" the record would be downloaded as CSV

If they click "Cancel" the dialog window will be closed

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

View solution in original post

7 REPLIES 7

Hi Ankur,

 

I created a ui page for the same, in Ui page when I tried it is working fine.

But when I tried from UI action nothing is happening

 

Can you please explain this more like your ui page name given and ui action details

Hi Parnika,

I would encourage to create a new question for this as it would be easier to keep track of.

please post the question link here and I can take a look on that

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Imatiaz
Kilo Contributor

Hi Parnika,

Please create a UI page with the name download_csv

download_csv