To load a JSON file in SCA using Suitescript 2. X

To create a suitescript 2 folder and service file for loading the file .

The code is added below

/**
* @NApiVersion 2.x
* @NModuleScope Public
*/
define(['N/record', 'N/render', 'N/format', 'N/search', 'N/file'], function (record, render, format, search, file) {
  "use strict";

  function fetchFile(context) {
    try {
      var FilId = context.request.parameters ? (context.request.parameters.internalid) : null;
      var fileObj = file.load({
        id: FilId
      });
      var contents = fileObj.getContents();
      var contentstringify = JSON.parse(contents);
    } catch (error) {
      log.error('dataParams er', error);
    }
    return context.response.write(JSON.stringify({ CommerceCategory: contentstringify }));
  }
  return {
    service: fetchFile
  };
});

We can fetch the data from the entry point or view file the. The method of fetching the data is added below

var Fields = SC.CONFIGURATION ? SC.CONFIGURATION.CommerceCategory.fileid : '';
							this.CommerceCategory = new CommerceCategoryModel({ id: Fields });
							var self = this;
							SC.CONFIGURATION.navigationData = []
							this.CommerceCategory.fetch().done(function (result) {
								console.log(result, 'this.model')
								SC.CONFIGURATION.navigationData = self.levelUpdate(self.CommerceCategory.get('CommerceCategory'))
								self.render();
							});

Leave a comment

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