Creating check upload button and getting image to NetSuite file cabinet

Using extension Suite script 1 how to add check upload button and store the images in NetSuite file cabinet.
View file:

define(
	'JJ.upload.check'
	, [
		'JJ.upload.check.View', 'OrderHistory.Details.View', 'jj_upload_check.tpl', 'Utils','jQuery', 'underscore' 
	]
	, function (
		checkView, OrderHistoryDetailsView, jj_upload_check_tpl, Utils, jQuery, _
	) {
		'use strict';

		return {
			mountToApp: function mountToApp(container) {
				// using the 'Layout' component we add a new child view inside the 'Header' existing view 
				// (there will be a DOM element with the HTML attribute data-view="Header.Logo")
				// more documentation of the Extensibility API in
				// https://system.netsuite.com/help/helpcenter/en_US/APIs/SuiteCommerce/Extensibility/Frontend/index.html

				/** @type {LayoutComponent} */
				var layout = container.getComponent('Layout');
				_.extend(OrderHistoryDetailsView.prototype, {
					template: jj_upload_check_tpl

					, events: {
						'click #upload-check-btn': 'openUploadCheck',
						'click #close': 'closeUploadCheck',
						'change #Check-input-file': 'filechanged',
						'click #check-submit-btn': 'uploadCheck'
					},
					openUploadCheck: function () {
						$("#container-upload-check").show();
						$(".order-history-details-order-contents").css('visibility', 'hidden');
						$(".order-history-details-back-btn").css('visibility', 'hidden');
					},
					closeUploadCheck: function () {
						$("#container-upload-check").hide();
						$(".order-history-details-order-contents").css('visibility', 'visible');
						$(".order-history-details-back-btn").css('visibility', 'visible');
					},
					filechanged: function () {
						var readerMTL = new FileReader();
						var self = this
						readerMTL.readAsDataURL($('#Check-input-file')[0].files[0]);
						readerMTL.onload = function (reader) {
							var mtlFile = reader.currentTarget.result;
							$('#Check-input').val(mtlFile)
						}
					},
					uploadCheck: function () {
debugger
						if ($('#Check-input').val()) {
							


							try {
								var checkData = $("#Check-input").val().split(',')[1];
								var imageName = $('#Check-input-file').val().split('fakepath\\')[1];
								var object = {
									checkData: checkData,
									imageName: imageName
								}
								var url = Utils.getAbsoluteUrl(
									getExtensionAssetsPath("services/check.Service.ss"))
									jQuery.post(url, JSON.stringify(object))
									.done(function (data) {
  										console.log('data', data)
										var data = JSON.parse(data);
										if (data.success) {
											swal.close();
										
										} else {
											var message = data.message || data.errorCode
											console.log('message',message)
											swal('Sorry!', message, 'error')
										}
									},"json");
							} catch (error) {
								console.log(error);
							}
						}

					}
				})
			}
		};
	});

define('JJ.upload.check'
,	[
		'check.ServiceController', 'SC.Model', 'Application', 'Utils', 'underscore'
	]
,	function (
		checkServiceController, SCModel, Application, Utils, _
	)
{
	'use strict';
	return SCModel.extend({

        name: 'JJ.upload.check',

        uploadCheck: function (data) {
			try {
				nlapiLogExecution('debug', 'data123', data);
				var checkdata = data.checkData;
				var imageName = data.imageName;
				nlapiLogExecution('debug', 'imageName', imageName);
				nlapiLogExecution('debug', 'checkdata', checkdata);
				 var checkImage = nlapiCreateFile(imageName, 'PNGIMAGE', checkdata);
                var setFolder = checkImage.setFolder(3318982);
				var checkImageId =  nlapiSubmitFile(checkImage);
				//var imgFullURL = document.querySelector('img.something').src;
			 } catch (error) {
			 	console.log(error);
			 }
		}
	})
});

Leave a comment

Your email address will not be published. Required fields are marked *