Scenario
NetSuite does not include a standard feature to keep track of how many times a file was downloaded from the file cabinet by a specific user, but it is possible to implement this feature by using a custom field and a Suitelet.
Instead of providing the direct link to the file, a link to a Suitelet can be provided. The Suitelet will update a custom field that will be used to keep track of how many times the file was downloaded and then it will return the file for download.
Solution
The steps below shows how to create a Entity Custom field (Download Counter) and a Suitelet. A link for the Suitelet can be made available in the Customer Center and the Download Counter field will be updated/incremented every time that the Suitelet is executed.
1. Create a custom field and apply it to Customers:
Label = Download Counter
ID = _download_counter
Type = Integer Number
Store Value = Checked
Applies To > Customer = Checked
2. Use the sample code below to create a Suitelet to update the Download Counter field and download the file:
function suitelet(request, response) {
// Link to a PDF file in the file cabinet
var fileLink =
"https://system.na1.netsuite.com/core/media/media.nl?id=20135&c=.pdf";
var response1 = nlapiRequestURL(fileLink);
// Change the content type according to the file
response.setContentType("PDF", "PDF File.pdf");
body = response1.getBody();
var downloadCounter = nlapiLookupField(
"customer",
nlapiGetContext().getUser(),
"custentity_download_counter"
);
if (downloadCounter != null) {
downloadCounter++;
} else {
downloadCounter = 0;
}
nlapiSubmitField(
"customer",
nlapiGetContext().getUser(),
"custentity_download_counter",
downloadCounter
);
response.write(body);
}