Custom Exports with JavaScript
  • 15 Mar 2022
  • 1 Minute to read
  • Dark
    Light

Custom Exports with JavaScript

  • Dark
    Light

Article Summary

Intro

ancoreShare Extension provides a JavaScript API to access the generated report file.
In this way you can export your reports for example to a custom URL, upload them on an FTP server, or anything else you can think of using JavaScript.

To enable custom export, perform the following steps:

Access export option
  1. On your Sense sheet, select the ancoreShare button for which you want to specify JavaScript export settings.
  2. On the properties panel, click Export Settings > Custom Export.
  3. Select the Enable Custom Export option.
Configure custom export

In the On After Export field, click fx to use the expression editor and enter your JavaScript code that will be executed on after the event of generating the report file there.

You will already find several examples and comments in this section to support you.

Sample Code

Here's a sample code that you can use to send the report to a custom URL.
In this sample, we have sent the exported file to Atlassian using a REST API.

/* Debug your code: Open browser developer console (F12): */
	//debugger

	//Upload file via REST Service
		const url = ""; // URL to REST Service
		const user = ""; 
		const password = "";
		
		let actionData=new FormData();
		actionData.append("file", file, filename);
		actionData.append("comment", subject);
		
		$.ajax({
			type: "POST",
			url: url,
			data: actionData,
			processData: false,
			headers: {
				"Authorization": "Basic " + btoa(user + ":" + password),
				"X-Atlassian-Token": "no-check",
				"cache-control": "no-cache"
			},
			contentType: false,
			cache: false,
			success: function (data, status, response) {
				webix.message({type: "success", text: filename + "
Custom Upload succeeded."});
			},
			error: function(response){
				webix.message({expire:-1, type: "error", text: filename + " Custom Upload failed.
" + (response.responseText || response.statusText)});
			}
		});
Info
Don't forget to update the variables as per your requirement.



Next Steps:



Was this article helpful?