Last active
August 16, 2018 02:29
-
-
Save benjsicam/6260155 to your computer and use it in GitHub Desktop.
This code is the Client Side Script for a NetSuite Wizard or NetSuite Assistant which has a File Upload functionality.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Executes when the wizard page loads. Binds a function/callback on the Browse button. | |
* @returns {Void} | |
*/ | |
function onPageInit() { | |
var fileUploadButton = jQuery('#browse'); | |
if (fileUploadButton.length == 0) return; | |
nlapiRemoveSelectOption('custpage_file', null); | |
nlapiInsertSelectOption('custpage_file', '', 'Please upload a File', true); | |
/* Bind the click event on the Browse button. */ | |
fileUploadButton.on('click', function () { | |
/* Determine the File Upload Suitelet URL. */ | |
var fileUploadSuiteletURL = nlapiResolveURL('SUITELET', 'customscript_file_upload_slet', 'customdeploy_file_upload_slet') + '&l=T'; | |
var width = 480; | |
var height = 200; | |
var left = (screen.width / 2) - (width / 2); | |
var top = (screen.height / 2) - (height / 2); | |
/* Open the File Upload suitelet on the center of the wizard screen. */ | |
window.open(fileUploadSuiteletURL, 'UploadFile', 'toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=no, copyhistory=no, width=' + width + ', height=' + height + ', top=' + top + ', left=' + left); | |
}); | |
}; | |
/** | |
* This is the function that will be called by the Suitelet when it is submitted. | |
* The suitelet will pass the ID of the file uploaded and it's file name. | |
* @param {String} fileId - The id of the file uploaded | |
* @param {String} fileName - The name of the file uploaded | |
* @returns {Void} | |
*/ | |
function setFile(fileId, fileName) { | |
nlapiRemoveSelectOption('custpage_file', null); | |
nlapiInsertSelectOption('custpage_file', '', 'Please upload a File', false); | |
nlapiInsertSelectOption('custpage_file', fileId, fileName, true); | |
nlapiSetFieldValue('custpage_file', fileId, true, false); | |
nlapiSetFieldValue('custpage_file_name', fileName, true, false); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment